Post new topic    
Liquid Metal Slime
Send private message
Manipulating Text Slices 
 PostThu Oct 02, 2014 5:36 am
Send private message Reply with quote
I couldn't find another thread for this, so I figured I'd make one.

I'm currently scripting a battle system for a game and I'm having trouble displaying the hp in the corner and the name of the enemy. Right now I have the blank text slices loaded up in a slice collection along with everything else in the battle scene. I figured this would be the easiest way to do it, rather than having to use show string at().

Here's what the script says now:
Code:

   col := load slice collection(0)
   append number(lookup slice(sli:hpcurrent,col),get hero stat(0,stat:hp,current stat))


I assume I'm not supposed to treat it as a string since it's a slice, but I don't know how else to add things to it. Do I not use append number()? Also how would I do the same with an enemy's name?
My pronouns are they/them
Ps. I love my wife
Metal King Slime
Send private message
 
 PostThu Oct 02, 2014 6:53 am
Send private message Reply with quote
That's right, text slices and strings are completely different objects. To set the text of a textslice, you use the set slice text command, after filing a string with the content you want. For example:

Code:
$0 = "Uglar"
set slice text(lookup slice(sli:enemy1,col), 0)  # string ID 0

$0 = ""
append number(0, get hero stat(0,stat:hp,current stat))
set slice text(lookup slice(sli:hpcurrent,col), 0)


Also, if you're using nightlies and you want to piece together long strings, you might find string sprintf useful. Example:
Code:
string sprintf(0, $0="HP: %d/%d", get hero stat(0,stat:hp,current stat), get hero stat(0,stat:hp,maximum stat))
set slice text(lookup slice(sli:hpcurrent,col), 0)
Liquid Metal Slime
Send private message
 
 PostFri Oct 03, 2014 12:18 am
Send private message Reply with quote
I didn't even see that command. Thank you very much.
My pronouns are they/them
Ps. I love my wife
Liquid Metal Slime
Send private message
 
 PostWed Oct 08, 2014 3:04 am
Send private message Reply with quote
I added more stuff to Stand. I figured out text slices, but making them children of each other doesn't work right, which is obvious if you go into a battle. They move and I'm not sure why.
My pronouns are they/them
Ps. I love my wife
Metal King Slime
Send private message
 
 PostWed Oct 08, 2014 6:02 am
Send private message Reply with quote
I had a brief look. The battle system is a cool project.

Why are you triyng to parent the text slices to one another? Is it get them to appear end-to-end? (Assume you just haven't set the anchor positions yet in the slice editor.) That will work, If you want to do that, just set up the parenting in the slice editor directly rather than with a script. The reason that the slcies move when you change the parent with setparent is that using setparent does not behave the same as setting a slice's parent in the slcie editor (with the shift key). A slice's x/y position is relative to its parent (or whichever edge or corner that might be). When you setparent a slice its position goes from being relative to the top left of th screen to relative to the new parent. On the other hand in the slcie editor when you reparent the offset is recalculated to keep the slice in the same position relative to the screen. Hint, you can press ctrl+F4 in game to investigate the slice tree.

I think I mentioned the alternative in another thread, "string sprintf"
Liquid Metal King Slime
Send private message
 
 PostWed Oct 08, 2014 2:26 pm
Send private message Reply with quote
Here is a handy little helper script if you want to reparent a slice without changing its current position.

Code:

script, set parent keep pos, sl, new parent, begin
  variable(oldx, oldy)
  oldx := slice screen x(sl)
  oldy := slice screen y(sl)
  set parent(sl, new parent)
  set slice screen x(sl, oldx)
  set slice screen y(sl, oldy)
end


You can use this command like this

Code:

set parent keep pos(myslice, new parent)


And it will be reparented pretty much the same way reparenting works in the slice editor.
Metal King Slime
Send private message
 
 PostWed Oct 08, 2014 9:24 pm
Send private message Reply with quote
To the Script dump!
Liquid Metal Slime
Send private message
 
 PostWed Oct 08, 2014 10:31 pm
Send private message Reply with quote
I could never figure out how to set parents in the slice editor. Now I know! That will be incredibly helpful in the future. Thank you, I will fix this.

EDIT: I want to set the numbers as parents because the number of digits will potentially change as the players HP increases or decreases.
My pronouns are they/them
Ps. I love my wife
Metal Slime
Send private message
 
 PostThu Oct 09, 2014 1:35 am
Send private message Reply with quote
I feel like we could make an actual hss or whatever file with a bunch of things, maybe organized by type... I know I have a bunch of slice functions I'm using in Silhouette that could be made more generic...
Metal King Slime
Send private message
 
 PostThu Oct 09, 2014 2:58 am
Send private message Reply with quote
kylekrack wrote:
I could never figure out how to set parents in the slice editor. Now I know! That will be incredibly helpful in the future. Thank you, I will fix this.

EDIT: I want to set the numbers as parents because the number of digits will potentially change as the players HP increases or decreases.


I assumed that you did it like that because you wanted the ability to make the numbers different colours (in which case, that's the best way to do it). If you don't want different colours, you can just use a single slice and "string sprintf", as I showed further up this thread.

Mystic wrote:
I feel like we could make an actual hss or whatever file with a bunch of things, maybe organized by type... I know I have a bunch of slice functions I'm using in Silhouette that could be made more generic...


Maybe! The 3rd party HSI did this long ago but is now fairly obsolete. If you just have some possibly useful but not generalised scripts, it's still nice to put them in the script dump or link to them from there (i.e. make the scripts freely available for use, so that someone else can clean them up and put them on the wiki).
Display posts from previous: