How do I return variable name as string?

  • Is it possible to convert a variable name into a string? Here's what I'm attempting to do with proximity checks. Based on if a boolean is true, it would append its variable name to a string variable. This long string would then be used to call one of many functions. Example:

    prox_Wall=true

    prox_Floor=false

    prox_Ledge=false

    prox_Ceiling=true

    Run check on all prox_variables to see what is true, remove "prox_" prefix and return string "var2str"

    varcheck(prox_)=var2str

    If function exists, run func_action(var2str)

    --or--

    varcheck(prox_)=WallCeiling

    If function exists, run func_action(WallCeiling)

    Or something like that. I suppose also, is it possible to query what variables are available, or would this be better to store all this in an array?

  • Nope. No way to reference the variable name.

    Best method would be to use an array where the indices are the variable names arrayAt(0) = prox_wall, etc.

    Use them in a container for automatic picking, or better yet use a string in a variable using tokenAt() with the method above.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Cool, thanks for the speedy reply!

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