How do I create a variable name from concatenated text?

0 favourites
  • 3 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I have two sets of objects/variables:



    berryGenNo (a variable)



    carrotGenNo (a variable)

    I thought I could write a function with 1 parameter for the 'fruit', and then be able to say, for instance,

    for 1 to fruitGenNo

    Pick a fruitGen

    Spawn a fruit

    But I can't seem to make the compound show up as a variable. Using fruit&GenNo or fruit&Gen doesn't work.

    Am I trying to do the impossible? This seemed to be a good use of functions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's not possible to access variables by names like that in events. Consider using a dictionary instead. With dictionary you can do Dictionary.Get(fruit&"GenNo")


    You can access variables by name using scripting:


  • Thanks for the quick reply.

    I think for this instance, I'll just have to duplicate events.

    Not surprised you can do it in scripting/js. I knew I could do it in Unity and c#!

    Glad I didn't spend too much more time on the impossible!

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