How do I slices

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

How do I slices

Post by Foxley »

After several months, I still don't quite understand how to work with slices. I'm reading through plotdict.xml and trying to figure out how to turn the scripting language entries into actual things relating to gameplay and maybe it's just sodium overdose from eating a bunch of pizza but I can't make sense of it.

Did someone make a noob tutorial about slices at any point already?
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Also maybe I should be specific on parts that don't make sense to me. One of the biggest ones is "handles". I don't really know what that even means.

And is loading a slice collection the same thing as putting it visibly on the screen? Or do you have to load it vicariously onto something else like a map layer # in order to display it?
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

Slices will make 0 sense until they make perfect sense. I know how you feel. Basically a handle is the name given to a slice that the computer can read. The handle has to be found by using something like 'lookup slice()' with which you can assign the handle of either a special slice (sl) or a custom slice (sli) to a variable.

This is why you see the syntax written as something like

Code: Select all

variable(sl)
sl := lookup slice(sl:textbox layer)
So what commands do is return something. 'get sprite frame()' returns the frame number of a sprite, 'mouse x' returns the x coordinate of the mouse, etc. 'lookup slice()' returns the handle of a slice. This is going to be the primary way that you call the handle of a slice, I think.

What this means is that when you're making you're own slices, you have to give each slice you want to manipulate individually a lookup code. After that, when you use lookup slice, you'll use "lookup slice(sli:my slice)" and attach that to a variable.

I hope this helps to conceptualize it a little bit :/

Do you know how the slice tree works, ie. parenting, and slice children?
My pronouns are they/them
Ps. I love my wife
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Good questions!

Firstly, a slice handle is a unique identifying number that refers to a particular slice. Its phone number, if you will. When you create a slice, it tries to write down that number for you: That's why most of the tutorials show something like

Code: Select all

variable (DemDigits)
SetVariable (DemDigits,CreateSlice (Whatever))
It gives you instant control and recognition of that slice. There's other ways to look up a phone number (Like a phonebook or "Hey blondie!") and that goes for slices too.

Loading a slice collection is absolutely the same as putting it visibly on the screen. The trick is that it's always on screen, like a smudge on the camera *until* you parent it to something more stationary like a map layer.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Cool, thanks. I'll try to process more of that tomorrow when I'm more awake.

I think I do, I grouped the N,S,W,E directional compass ellipse slices in the HUD slice collection into a container so I can shift them around without getting them jumbled up. Then I made a 4x3 grid for the inventory/spell box so there are 12 rectangles all lined up. As far as how that's going to work in plotscripting? I have no idea.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I feel that the Slices Tutorial on the wiki is halfway between a tutorial and a manual explaining the different slice types and slice concepts like anchors, and really needs pictures and more follow-along examples. And the examples in the Plotscripting Dictionary certainly aren't meant to be a tutorial.

Have you looked at BMR's Simple Slices Tutorial? That one is actually intended as a tutorial. I admit I haven't read right through it, but it seems like a good place to start.

Note that Kylekrack's talk of lookup codes is pretty focused on using the slice collection editor. You don't have to use the slice collection editor at all if you prefer creating slices directly with script commands like "load walkabout sprite".
Last edited by TMC on Mon Jun 08, 2015 12:33 pm, edited 2 times in total.
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

TMC wrote:Note that Kylekrack's talk of lookup codes is pretty focused on using the slice collection editor. You don't have to use the slice collection editor at all if you prefer creating slices directly with script commands like "load walkabout sprite".
Yeah sorry about that. That's what I personally use and what I find to be most useful, especially when making GUI and things like that, which stay on the screen. It's also good because you can parent slices much more easily, which clears up the scripts a bit. And with grids and things you can adjust padding and alignment and anchoring to automatically format text and other slices, saving a lot of time and trial and error.

Basically what you have to keep in mind with parenting is that when a slice is a child of another slice, its position is different from its screen position. This means that any change in position will be relative to the parent, which can be a great thing and an annoying thing. There are also plenty of commands in the dictionary that reference the hierarchy of slices in the tree, and when you understand parenting you can take advantage of them. The only advice I have for that is reading the dictionary. The plotscripting dictionary, don't be going to Webster. That dictionary is not fun to read.
My pronouns are they/them
Ps. I love my wife
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Oh, using the slice collection editor is definitely the way to go most of the time, didn't mean to imply otherwise. Even if I write a bunch of slice commands to manually create and edit slices, it's likely that I'll test it out in the slice editor first to check the positions and anchors and so on are right.
Last edited by TMC on Sun Jun 14, 2015 9:38 am, edited 1 time in total.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

I'm trying to free slices for submenus when another submenu button gets clicked. The part where it loads the slice collection when clicking a submenu button works fine, but the other submenus (which take up the same screen area) are visibly not going away. Excuse the inconsistent looking organization:

Code: Select all

script, active menu command, button, begin
	if (button == sli:inventory) then (
		load slice collection (1)
		if (slice is valid(sli:spellcontainer)) then (
			free slice (sli:spellcontainer)
		) else if (slice is valid(sli:floppycontainer)) then (
			free slice (sli:floppycontainer)
		)
		
	) else if (button == sli:spellbook) then (
		load slice collection (2)
		if (slice is valid (sli:itemcontainer)) then (free slice (sli:itemcontainer))
		else if (slice is valid(sli:floppycontainer)) then (free slice (sli:floppycontainer))
	) else if (button == sli:floppy) then (
		load slice collection (3)
		if (slice is valid (sli:itemcontainer)) then (free slice (sli:itemcontainer))
		else if (slice is valid(sli:spellcontainer)) then (free slice (sli:spellcontainer))
	)
end
Is this because "load slice collection" and "free slice" have nothing in common with eachother? If so, is there something along the lines of "unload slice collection"?
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I am typing from my phone, so I can provide a detailed example today, but you are using slice lookup codes in places that expect slice handles

They are NOT the same thing

The sli:name lookup codes are only used for the "lookup slice" command. All the other slice commands require slice handles

Also, there is almost never any good reason to use the "slice is valid" command. I need to update the docs to make it clear that command is only really there for debugging.

I can try to give you a corrected example in a few days (unless somebody beats me to it)
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

You should start by replacing every occurrence of "sli:something" in your script with "lookup slice(sli:something)".

However, it would be pointless (though completely correct) to write "if (slice is valid (lookup slice (sli:itemcontainer)))". You should just write "if (lookup slice (sli:itemcontainer))" because lookupslice returns 0 if the slice doesn't exist. If lookupslice returns a slice handle rather than 0, then it's always a valid slice handle.

I've updated the plotscripting dictionary to explain why you should not use sliceisvalid, and tried to explain slice handles a little. Until the nightly copy of the dictionary is updated, you can read the explanation here:
http://tmc.castleparadox.com/ohr/temp/p ... iceisvalid

Off the top of my head, I can't think of anything sliceisvalid is both useful and safe for. But I should mention this is just a limitation of the current script interpreter. When we switch to a new script interpreter with garbage collection, sliceisvalid will become a safe and useful command.
Last edited by TMC on Sun Jun 14, 2015 10:56 am, edited 2 times in total.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Points taken.

I've been messing around and am still unable to find a way to make a slice collection loaded into a variable remove itself from the screen. When I do "free slice (sl)" it either says "unknown slice handle 0" or does nothing. I checked the slice editor with F8 and sure enough it's loading an extra copy of the submenu slice every time the HUD button is clicked.

Code: Select all

 .......
			) else if (mouseclicked (sli:inventory, hud)) then (
				active submenu (1)
			) else if (mouseclicked (sli:spellbook, hud)) then (
				active submenu (2)
			) else if (mouseclicked (sli:floppy, hud)) then (
				active submenu (3)
.......


script, active submenu, submenu, begin
	variable (sl)
	
	if (sl) then (
		free slice (sl)
		sl := load slice collection (submenu)
	) else (
	sl := load slice collection (submenu)
	)
	
end
If I omit the "if (sl) then (" part and just try to free the slice before loading the intended collection, it says:

freeslice: invalid slice handle 0

Call chain (current script last):
autorunscript -> activesubmenu



However, for testing purposes, I did this:

Code: Select all

script, active submenu, submenu, begin
	variable (sl)
	
	sl := load slice collection (submenu)
	wait (10)
	free slice (sl)
	
	
end
And it does visibly load the submenu, wait a half second, then free it. Is the variable in "active submenu" losing its slice handle every time the script is run? I'm guessing that's what's happening. As far as how to remedy that, I have no idea.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Yes, that is a local variable, it only lasts for a single run of the script. You probably want a global variable
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Used a global variable and oh my god it works now. THANKS JAMES!
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Yay!

I am looking forward to seeing your game :)
Post Reply