Create Objects from Variables?

  • Hello,

    perhaps Im thinking too java, but is there any way to store objects or their identifiers in a variable and create them with these informations? Till now Im just able to create an object over the system-action, but in this case you cant use a variable/string.

    Case: Create Arrow depending on the ammo you have (many possible ammos!). After Creating it, there should be some actions, like turning, setting velocity... so I don't want to test all possible ammos with a condition and than turn and move them like:

    if ammo1--> create arrow1,turn, setvelocity,move

    if ammo2 --> create arrow2, turn, setvelocity, move

    ...

    I just thought about making a ghost arrow and put the different arrows in a family and both in a container.

    but that would be even a lot of conditions with just one action:

    if ammo1--> create arrow1

    if ammo2--- create arrow2

    turn, setvelocity,move container

    im searching for this:

    create object("identifier")

    turn, setvelocity, move object

    Or any other idea?

    Thank you very much!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You would probably want to create 1 arrow sprite. Set each frame of it do a different graphic. Then give it some basic stats like damage, speed, etc.

    Then create a function called "CreateArrow"

    Whenever you want to spawn an arrow you would call that function, and all of the parameters would be based on the parameters you specify when you call it.

    In the function would you setup a bunch of IF statements to determine which kind of arrow will be generated.

    On call function "CreateArrow" , " poison", "300", " 10 "

    If function.param(0) = "poison" -> set damage to 100

    if fucntion.param(0) = "fire" -> set damage to 200

    blah blah blah...

    create object "arrow"

    set arrow.type = function.param(0)

    set arrow.damage = function.param(1)

    etc etc

    Another option is to look into the "nickname" plugin by rexrainbow

    you can create objects ahead of time with different stats/looks, and give them a nickname that you can call at any point similar to the way you described

  • Thanks for the detailed response. I think the idea with the images would work fine/best, even if it feels a bit weird to solve it this way, but if there is no build in solution... it will fit I guess. But it's good to know that there isn't and I'm not building any creepy stuff, if it would have been one click .

    But I will take a look at the plugin too.

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