Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: tor.brandt on Mon 24/10/2016 14:23:21

Title: String with two string variables
Post by: tor.brandt on Mon 24/10/2016 14:23:21
I'm trying to modify the LW_BASS module, such that when an inventory item is active, the action text will display "Use [active inventory item] with [the hotspot/object/etc. which the cursor is currently over]".

What is wrong with this line:
Code (ags) Select
lblActionText.Text = ("Use %s with %s", player.ActiveInventory, Game.GetLocationName(mouse.x, mouse.y));?

AGS says there is a parse error.
Now, there may be other errors, and I'm not even sure if I'm using player.ActiveInventory and/or Game.GetLocationsName() correctly here, but I just can't see the parse error.
Title: Re: String with two string variables
Post by: Crimson Wizard on Mon 24/10/2016 14:32:30
Firstly, idk if that is a typo, but you are not calling actual function, just typed parameters to it. You are missing "String.Format" before opening bracket.

Code (ags) Select

lblActionText.Text = String.Format("Use %s with %s", player.ActiveInventory, Game.GetLocationName(mouse.x, mouse.y));


Secondly, ActiveInventory cannot be converted to string using "%s", because its.... well, InventoryItem, not String. You probably need player.ActiveInventory.Name.
NOTE: you may not get any compile errors using just player.ActiveInventory, but the actual outcome will be either runtime error, or some garbage printed instead of meaningful string.
Title: Re: String with two string variables
Post by: tor.brandt on Mon 24/10/2016 14:47:19
Oooh I see, I wasn't aware that I needed the String.Format part.

And thanks for the player.ActiveInventory.Name correction, now it's working perfectly :smiley: