How to show string-var in textbox?

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

Moderators: marionline, SDHawk

Post Reply
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

How to show string-var in textbox?

Post by marionline »

I'm trying to get text as $string into a textbox.
I'm somewhat clueless here ... maybe it's just a something like spelling mistake, that I don't see?

I wrote a script show_text:

Code: Select all

 
script, show_text, itemid, begin
    $200="You created %s!" 
    string sprintf(200, 200, get item name(itemid))
    show textbox (230)
    wait for textbox
end    
Image
That's the textbox what should show the string variable.

This is the script to call the show_text script:

Code: Select all

 
script, craft_amulett_of_fire, begin
  delete item(item:Stone)
  delete item(item:Thread)
  delete item(57)
  get item(32) #create item no 36
  
  show textbox (232)
  wait for textbox
  show_text(57)
  
end
Image
And that's what is shows in the editor
when the script is run. No variable is shown.

Image
Only the text box and textboxtext is displayed if script is started by NPC.

The sting is never displayed in textbox, not even the first part of it. :???:
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

"string sprint" doesn't allow you to use the same string ID for both the destination string I'd and the format string ID

I usually write it like:


Code: Select all

string sprintf(0, $1="Formatted value %d", Val)
Last edited by Bob the Hamster on Tue Nov 29, 2016 1:52 pm, edited 1 time in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks for your answer. :)
Is it's string sprintf(id-of-old-string ,id-of-new-string, Val), right?

Unfortuntely, even the change string part commented out, the textbox does not display the string variable.

Code: Select all

script, show_text, itemid, begin
    $200="You created SOMETHING COOL." 
    #string sprintf(201, $200="Formatted value %d", get item name(itemid))
    show textbox (230)
    wait for textbox
end    
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

it is:

Code: Select all

string sprintf(id of string to create, id of string containing format, value)
But I just spotted the other two problems in the script.

"get item name" requires a string id.

and %d embeds an integer, but you need it to embed a string with %s

Code: Select all

string sprintf(0, $1="Item name: %s", get item name(2, itemid))
So there are actually 3 string ids being used here. In my example above, the finished ready-to-display string ends up in string id 0
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks a lot! :D
I finally got the textbox that is displaying the item name.
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Bob the Hamster wrote:"string sprint" doesn't allow you to use the same string ID for both the destination string I'd and the format string ID
Not true, they can be the same.

The main reason that your script didn't show anything at all is that 200 isn't a valid string ID. Strings have IDs from 0 to 99.

Apparently you didn't get an error message about that mistake because you weren't using "Test Game". If you aren't using the Test Game feature, then I strongly recommend you manually turn on error reporting by going to Edit General Game Data -> Plotscript Error Display and setting "Script Error Display Mode" to "debug".
You should turn error reporting back off before releasing your game.
Post Reply