How do I choose from a global variable string?

  • Hi guys!

    I'm a bit stuck with this one:

    I'm loading functions names from a dictionnary to a global variable, and call them into a choose action to randomly choose some fonctions.

    But for some reasons, construct seems to ignore my request, do you have any idea? every 2 sec > choose("pointYellow","pointRed"levelSelect)

    Level select is the global variable The global variable contain something like ,"pointGreen","pointPink" (with quotes and comas)

    WHY? :/

    Thanks!

  • Function name in the variable should not contain quotes or commas. If your variable contains a comma-separated list of function names, then you can't use it in choose() expression like that. Instead, parse it with tokenat, for example:

    Set list to "FunctionA,FunctionB,FunctionC"
    Call function tokenat(list, int(random(tokencount(list,","))), ",")
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you very much for the reply!

  • Just to let you know, a choose on a tokenat was the key to my problem! Thank you, I learned a lot!

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