How do you show a global value in text slices?

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

Moderators: marionline, SDHawk

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

How do you show a global value in text slices?

Post by Foxley »

I'm able to do things like ${V1} in text boxes to show the value of global variables, but how do you do the same thing with text slices? I want to show the value of a global in the slice collection editor, hopefully this is something that's doable. Otherwise I guess I can script text slices manually and have it copy values from a text box with ${V_} in it. As hacky as that would be.
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

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

Post by Foxley »

I guess I more meant is there a way to display global values via text slices in the slice collection editor, specifically. That way I don't have to script and manually position a string or text slice on the screen using Hamsterspeak, which would be fairly annoying. I'd like to do this to show the amount of consumables and money on the HUD in the game I'm working on, and when I do ${V1} or the like, it just shows that exact syntax, not the value that it gets converted to like in text boxes.
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Well, I've never used this command, but I've seen TMC do it and it was dope as slime. StringSprintF. I'm sure there's a programmery reason it's called that, but I got no clue.

When I did Karate Fight, I had the same problem you're having now and the way I did it was with ExpandString. I do admit it was a pain in the slime, because I had to have like a second text string as a buffer. It worked like...

Code: Select all

#BigBoss was an invisible textslice that was like Atk: ${v1} or however that works.
#WhichOne was a visible textslice

BigBoss := lookupslice (36)	
whichone := lookupslice (10)

#Get that Atk $V1 stuff from BigBoss.. I name my variables like that sometimes... 
getslicetext (0,BigBoss)

#Expand the V1 into something useful
expandstring (0)

#And visualize it in the WhichOne slice
setslicetext (whichone,0)
But yeah, as for doing it in the slice collection editor, I'm not sure it's possible/easy.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Text slices should be made to parse those codes automatically, just like textboxes and menu items do. I've been meaning to do it for a while, and it would actually be really quick for me to implement that, if you're willing to use a nightly.

Otherwise, you could write a script to scan a slice tree for all text slices and run 'expand string' on all of their contents. That would be a fairly short script, and it would be completely general. You don't want to use stringsprintf* in this case, because it uses different codes (like %s instead of ${V#}).

*sprintf is short for "PRINT Formatted text to a String", and I confusingly tacked on 'string' because it uses string ids instead of 'real strings' (which HamsterSpeak doesn't have yet).
Post Reply