create objects dynamically

Get help using Construct 2

Post » Wed Oct 02, 2013 2:20 pm

how do i create
say 35 objects(sprites that act as buttons)
and controlling its state(selected/clicked)?
im thinking to do a for loop 35 times and create objects then i want to store the any action in an array so i know that number 5 was clicked
but i cant seem to find a way of creating objects with names i can use dynamically, so that in another loop i can check value of each button
(each button should have the name i(number from loop),
so far i've created a sprite,a textbox and made them into a container.
now i need to find a way to render them in a loop, but each button should be controlled separately,
yes its easy to do manually but if there is a way to make it programatically, im all for it.
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Oct 02, 2013 2:45 pm

hahahah, this is exactly what I'm looking for in the post I made.
You can check my CAPX (I went ahead on the manual mode) :P

Because I couldn't figure it out either
http://www.scirra.com/forum/topic76631_post458784.html#458784
B
4
Posts: 25
Reputation: 425

Post » Wed Oct 02, 2013 2:56 pm

Could you use one sprite with 35 animation frames, then use the animation frame as the identifier - they could then be created in a loop. You could even pass the animation frame to the array.
B
8
S
2
G
1
Posts: 45
Reputation: 1,007

Post » Wed Oct 02, 2013 2:56 pm

Just thinking out loud:
Would it work using a local variable which you add 1 to in each loop and set an instance-variable to that local variable on creation?LittleStain2013-10-02 15:08:10
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Oct 02, 2013 3:09 pm

im not sure what you mean, but i dont think so based on the fact that i cannotuse the variable to get the container
i need to link the variable i to the container so that i can read and modify the container
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Oct 02, 2013 3:16 pm

You want to be able to set a variable, but you can't use the variable?

I don't see the logic..
If every object in the same container has the same instance variable, wouldn't that be usefull?

If you would use a local variable that is a number you could set a text-variable by setting its text to: "i"&localvariable

so for the first one the text variable would be "i1", the second "i2", etc..

But it seems I'm not understanding your question..

And I'm even starting to question my own logic, haha..LittleStain2013-10-02 15:23:59
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Oct 02, 2013 3:26 pm

Piotr,cool!
do you mind spilling the beans?
I couldn't find anything on your link that pertained to this problem.
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Oct 02, 2013 3:35 pm

[QUOTE=LittleStain] You want to be able to set a variable, but you can't use the variable?

I don't see the logic..
If every object in the same container has the same instance variable, wouldn't that be usefull?

If you would use a local variable that is a number you could set a text-variable by setting its text to: "i"&localvariable

so for the first one the text variable would be "i1", the second "i2", etc..

But it seems I'm not understanding your question..

And I'm even starting to question my own logic, haha..[/QUOTE]
but i cannot access the object by "i1"..
so setting a instance variable doesn't help me making 35 unique buttons
I need to be able to make button 10 to light up, i need to catch input like button 35 was pressed.
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Oct 02, 2013 3:48 pm

This event should do it:

-on button clicked
-button instance variable is "i10" ---> button light up

instance variables are a perfectly fine way to see which instance of an object is being interacted with in my opinion.
LittleStain2013-10-02 15:51:14
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Oct 03, 2013 2:10 pm

to clarify the purpose of this application:

I am making a lottery picker where you select 4 numbers from 1 to 35 and press go, upon go I make a ajax request to my server who will respond with the winning combination, then a wining animation will be displayed on those winning numbers.
.
to make 35 buttons and have them highlighted when clicking is no problem but now I muust take result from server and generate selected winning numbers animation but how can I reach these objects who are all instances but have an instance variable (between 1 and 35 as identifier)
How do I capture an object based on instance variable?
B
9
S
2
Posts: 76
Reputation: 709

Next

Return to How do I....?

Who is online

Users browsing this forum: JaredX, jkmalau and 10 guests