Global variable

For questions about using Classic.

Post » Tue Oct 11, 2011 4:36 pm

I have two text objects, "r1" and "r2".
And if this is true:

left(r1.text, 1) == "{"
right(r1.text, 1) == "}"

Then this happens:

r2: set text to left(r1.text, len(r1.text)-1)
r2: set text to right(r2.text, len(r2.text)-1)

Here is the problem:

I want the the text returned by r2 to to be replaced by a global variable with the name extracted by r2.
I need this so my external files that are dialogues can show variables from the game, which could look like {kills} or {player name}.
So how can i do that?

I have tried global(r2.text) but it doesent work...
B
18
S
4
G
1
Posts: 413
Reputation: 2,512

Post » Tue Oct 11, 2011 9:11 pm

Really confused but is this what you're looking for?

say there's a player name "bob"

Then what you're saying is that his name will be something like "{bob}" in your game. If that is so then using your method the tags are removed and is left with "bob".

If so what you're trying to do is call a global variable global("bob"). Problem is I don't know if you already have a global variable "bob". Unfortunately I don't know how to create global variables in run time. I don't think you can. I can do it within python but that's separate from CS and will be some what a 'private' variable in essence.

Global() is just a call function. If I miss understood and you already have a "bob" global variable and/or know how to implement it in run time I can only say: have tried adding quotation marks around r2.text? Like global('r2.text')?
B
3
G
1
Posts: 44
Reputation: 563

Post » Tue Oct 11, 2011 9:22 pm

The variables should exists already, and should not be created at runtime. I just want {ANY VARIABLE NAME} to be replaced by a already existing variable with the name that is r2.

I have tried global('r2.text')? . It does not work.
B
18
S
4
G
1
Posts: 413
Reputation: 2,512

Post » Tue Oct 11, 2011 9:40 pm

The Global() expression only takes a valid global name, it can only take a string from python. A solution would be to use a global hashtable object.
B
79
S
24
G
55
Posts: 4,755
Reputation: 41,273


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests