0 Favourites

How create obj by name?

  • How create obj by name?

    thanks for support.

  • Add Event

    Then add action

    Action (system --> create object)

    Then choose object to create

    Set layer (through layer name)

    Set X and Y

    Hope this is what u are looking for.

  • Add Event

    Then add action

    Action (system --> create object)

    Then choose object to create

    Set layer (through layer name)

    Set X and Y

    Hope this is what u are looking for.

    thanks you. but.

    I have a variable on the object(1), this variable can be named object(2).

    I need to create the object(2) with that name.

    how?

  • For that i dont have the answer.

    If i usualy need specific instances i just create more then one of the same object, and then pick the instance out of those that i need.

  • For that i dont have the answer.

    If i usualy need specific instances i just create more then one of the same object, and then pick the instance out of those that i need.

    For example:

    I have an object with variable slot1.

    Event

    right click

    -if (obj.slot1 == 'bullet1') then

    -- spwan bullet1 object on layer ....

    -if (obj.slot1 == 'bullet2') then

    -- spwan bullet2 object on layer ....

    My problem is I have more than 50 bullet.

    <img src="smileys/smiley19.gif" border="0" align="middle" />

  • Do you really need 50 different objects ?

    You could use a single sprite with 50 different animation frames, and on creation of the bullet make something like :

    Bullet.Animationframe = obj.instanceVariable

    Where instance variable is a number corresponding to the frame.

  • This isn't supported because as part of minifying and obfuscating your project on export, object names are removed to make it even more difficult to reverse engineer a project.

    Allowing creating objects by a variable would then force C2 to include the original names of all objects, possibly making it easier to reverse engineer the project. TBH I think the best solution is a series of subevents like you've shown.

  • Do you really need 50 different objects ?

    You could use a single sprite with 50 different animation frames, and on creation of the bullet make something like :

    Bullet.Animationframe = obj.instanceVariable

    Where instance variable is a number corresponding to the frame.

    thanks. a good idea.

    I use obj because each object has a few initial values such as name, mindag, maxdag, firerate, speed, ...

  • Allowing creating objects by a variable would then force C2 to include the original names of all objects, possibly making it easier to reverse engineer the project.

    Uh, I understand, it's a trade-off.

    I had try to create instance by name before (in plugin), but fail.

  • I use obj because each object has a few initial values such as name, mindag, maxdag, firerate, speed, ...

    Hold the initial values in an array and apply it on creation of the instance.

    Once again, obj.instanceVariable can act as the index for an array.at(obj.instanceVariable)

  • Ashley

    Is there no way to to do this using a variable or expression?

    Its actually quite useful when creating a group of objects together.

    Grouping for instances with different frames is problematic, plus that does nothing to help when you have to have different objects, tiled bg, sprite, particles... all together.

  • newt, if it was done the runtime would have to include a table of all object's correct names, which would help reverse engineers.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I have similar and made it

    I have several Guns that need to spawn correct bullet type:

    I did it like this:

    Object Gun with animations (gun1,gun2,gun3,etc)

    Then:

    Object Bullet with several animations (bullet1,2,3,etc)

    Global Text variable (type of variable depends on what you are doing)

    Guntype=gun.animationname

    Then

    If guntype="animationx"

    set bullet animation = guntype

    i had to use a variable for other reasons, you could even set animation to gun.animation on every tick

    Hope this helps

  • What about something like create by id, possibly assigning an id during runtime?

  • Yes I need this feature too; I ended up with a long "switch" (as in the programming structure) that I keep adding to whenever I need a new object type created by the "factory".

    Is it possible to create by "class ID" or something?

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