Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fever44 on Thu 25/05/2023 17:15:51

Title: using player.ActiveInventory.Name from Global Script
Post by: fever44 on Thu 25/05/2023 17:15:51
I am trying to write a function in the global script that I can call from any of my rooms that will display "use INVENTORY ITEM on HOTSPOT", eg: "USE BLUE MUG ON ROCK". However, when I use player.ActiveInventory.Name from the global script, the value is always 0. If i make the same call from my room script, the value is correct - the actual name of the inventory object.

I was having this same issue with hotspots as well. What am I missing here?

Thank you!
Title: Re: using player.ActiveInventory.Name from Global Script
Post by: eri0o on Thu 25/05/2023 17:49:27
In which function in global script are you using this? What do you mean by the value of name is 0?
Title: Re: using player.ActiveInventory.Name from Global Script
Post by: fever44 on Thu 25/05/2023 18:48:01
Thanks for the response. I made my own function and added it to the global script. When I assign 'player.ActiveInventory.Name' to a String and use Display() to display the String, it outputs "0" or "0.0000000f". However, if I move the code to my room script, it works as expected and outputs the actual name of the inventory item.


Title: Re: using player.ActiveInventory.Name from Global Script
Post by: Khris on Fri 26/05/2023 14:50:47
You need to use %s to insert a string value into text, it looks like you've accidentally used %d or %f.
Please always show your code when asking about coding.

https://adventuregamestudio.github.io/ags-manual/StringFormats.html
Title: Re: using player.ActiveInventory.Name from Global Script
Post by: fever44 on Fri 26/05/2023 15:34:44
Thanks Khris, you nailed it; that is exactly what I was doing wrong. Appreciate your help!