Global variable

This forum is currently in read-only mode.
  • 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...

  • 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')?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)