How do I use instance variables in text from a project file?

Get help using Construct 2

Post » Mon Oct 09, 2017 10:10 pm

Currently I am using an XML file to store dialog. However, I'm having trouble using that to call instance variables.

An example:

In the XML file there might be text like "Hello, Player.name", and when I print that, the text reads as 'Player.name' instead of the 'name' value stored in the Player object. I'm wondering if there is a way around that.
B
13
S
5
Posts: 7
Reputation: 982

Post » Tue Oct 10, 2017 1:27 am

Yeah, it doesn't work like that.
You need to insert player's name into the text using events.

Change you text in the XML to something like this:
"Hello %player%, you have %gold% coins."

Before displaying the text on the screen you need to search for %player% and %gold% tags and replace them:

message= Replace(message, "%player%", Player.Name)
message= Replace(message, "%gold%", str(Player.GoldAmount))
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,401
Reputation: 84,429


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests