Picking Expression Spawned Objects

This forum is currently in read-only mode.
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • So I'm trying to spawn objects by expression to try to streamline my events, but I've run into a little problem. As far as I understand, under normal circumstances when you spawn in object in Construct that object is automatically the one picked for any following actions, which is cool. However, I don't know how to modify that same object if the object created is through a string variable in an expression. Basically...

    I want to do

    Player presses Attack Control

    --> Player create object Player.Value('CurrentWeapon')

    --> Set (Player.Value('CurrentWeapon').Value('Power') = blahblahblahstupidmathblahblahblah

    I don't want to do, but will I guess if I have to

    Player presses Attack Control

    --> If Player.Value('CurrentWeapon') = WimpyGun

    ----> Player create object WimpyGun

    ----> Set WimpyGun.Value('Power') = blahblahblahwimpymathblahblahblah

    --> Elseif Player.Value('CurrentWeapon') = NotWimpyGun

    ----> Player create object NotWimpyGun

    ----> Set NotWimpyGun.Value('Power') = blahblahblah1337mathblahblahblah

    --> Elseif etc..., etc...

    ----> blahblahblahlotsofeventsblahblahblah

    Am I just gonna have to suck it up and make a condition for each object as outlined in Example B? <img src="smileys/smiley19.gif" border="0" align="middle" /> Or is there a way to make Example A work?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why not just use a loop?

    You can use numbers as names of private variables, or even concatenate numbers in names of private variables.

    IE sprite.value("guntype"&loopindex("n"))

  • There is a system expression that reads like "Create by name", use that and then put an action for each type of gun to set its power to the math you use. For some reason this only selects the object you just created, might be the way "Create by name" works.

    Note that actions which apply to a family the object created by name is in do not affect the created object. Again, I don't know why.

  • newt

    I'm not sure what I'd be looping in this case to pick the correct object when there might be multiple instances of it on screen?

    Jayjay

    I knew about the Create Object by Name, didn't know it did that though. It'd be useful if it were just a few guns and all I was doing was a quick Power calculation, but I'm also setting a Character ID, an Attack Type, and an Element, and doing a further modifier on the Power in the case of a certain status condition. Also, your suggestion pretty much equates to the same thing as Example B, except it'd be a bit more unreadable having it all in one long event due to the amount of weapons and variables that are to be involved.

  • newt

    I'm not sure what I'd be looping in this case to pick the correct object when there might be multiple instances of it on screen?

    Jayjay

    I knew about the Create Object by Name, didn't know it did that though. It'd be useful if it were just a few guns and all I was doing was a quick Power calculation, but I'm also setting a Character ID, an Attack Type, and an Element, and doing a further modifier on the Power in the case of a certain status condition. Also, your suggestion pretty much equates to the same thing as Example B, except it'd be a bit more unreadable having it all in one long event due to the amount of weapons and variables that are to be involved.

    Ahh okay, well then Example B is the only option I guess, if it was a simple 1 line calculation for each it wouldn't be so bad.

  • It's no simple 1 line calculation, but here is one way to do it.

    http://dl.dropbox.com/u/5426011/examples7/createbyname.cap

  • Beautiful, R0J0hound, beautiful! It works pretty flawlessly so far. Can't thank you enough!

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