Picking Expression Spawned Objects

For questions about using Classic.

Post » Sat Oct 01, 2011 1:02 am

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? Or is there a way to make Example A work?
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Sat Oct 01, 2011 1:15 am

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"))newt2011-10-01 01:20:50
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Oct 01, 2011 1:33 am

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.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Sat Oct 01, 2011 2:00 am

@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.
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Sat Oct 01, 2011 2:20 am

[QUOTE=TL22] @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.[/QUOTE]

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.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Sat Oct 01, 2011 3:22 am

It's no simple 1 line calculation, but here is one way to do it.
http://dl.dropbox.com/u/5426011/examples7/createbyname.cap
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Sat Oct 01, 2011 7:58 pm

Beautiful, R0J0hound, beautiful! It works pretty flawlessly so far. Can't thank you enough!
B
58
S
20
G
7
Posts: 305
Reputation: 8,804


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests