Picking an object from multiple of same object with keyboard

For questions about using Classic.

Post » Sat Jun 28, 2008 3:52 pm

I am trying to figure out how to picking an object from multiple of same object with keyboard.

Let us start here.

We make a loop to make a object/sprite(tank) lets say 8 times.
The first one is the default object/sprite(tank) out of the group of 8. It is the one the editor uses when you pick the object/sprite(tank) to do something to, like have the game scroll to the object/sprite(tank) so you can keep it centered on the screen.

What I need to find out how to do is how to make the other object/sprite(tank) 2 - 7 of 8 the default one.

What I like to do is push F2 and make object/sprite(tank)2 the default. Make it so that object/sprite(tank)2 can move and the other object/sprite(tank) of the 8 don't.

Then be able to do the same thing for all 8 object/sprite(tank). By pushing F1 - F8.

Can this be done? or do I need to make each tank a different object.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sat Jun 28, 2008 5:57 pm

Max,

you forgot to specify the question like ..

can i do this without rewriting my events in the .cap you will find at
viewtopic.php?f=3&t=1166

the answer is: yes, but rather not.

You will have to start using containers, as i stated already to simplify the pick events.

Due the way your events are organized, and because i did not see to much beginner errors in your . cap, i assumed you was already on a higher level then i am.

Now i know better.
May i suggest you read the beginners guides i wrote, while i come up with a new topic about using containers.
After i finished this topic, i come back to your question, if you did not find the answers by yourself already then.

Greetings.
B
3
S
2
G
4
Posts: 322
Reputation: 2,119

Post » Sat Jun 28, 2008 6:21 pm

The way I would do this is add a private variable to your Tank sprite called 'ID'. Then, add an event like:

+ Start of Layout
+ For Each Tank
-> Set 'ID' to LoopIndex

This assigns the tank IDs 1, 2, 3, 4...

If you want to pick the second instance, just use a 'Compare private variable' condition, and compare ID equal to 2. For example:

+ Upon pressing F2
+ Tank ID = 2
: Scroll to Tank

This scrolls to tank #2.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sat Jun 28, 2008 10:39 pm

Thanks Ashley and you too TheInstance,

That was the last bit of info I needed to get my head around this problem. I have a link to my little CAP I did to show how this works.

Let me know if I can streamline this any. I think in the Key check I can go to one check for each key instead of the two I have now.


Link: [url:pi7oc7oy]http://www.savefile.com/projects/808655567[/url:pi7oc7oy]
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sat Jun 28, 2008 10:52 pm

Some of the For Each loops are redundant. In the group 'Pick tank to scroll to', the condition 'TankID' equal to global('LastPickedTank') already checks every Tank to find the one(s) with matching values, so the For Each has no effect. Also, in the group 'Pick tanks', every single For Each is redundant and can be deleted: remember the way conditions work normally, there is an implicit for-each since it checks if the condition is true for every instance, then applies the actions to all the instances that met the condition. In this case, the events work fine without a for-each!
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sun Jun 29, 2008 6:02 pm

Ashley I can use your help.

I put the same code in my main program as I did in my little demo above. But something is up with the loop .

I should get tank 1,2,3,4,5,6,7,8

But I am getting tank 8,1,2,3,4,5,6,7.

I can not see why this is happening.

The other thing that is happening is when you push F7 you are getting a VRAM Usage Window pops up. That only happens with F7, and not with the other Fn keys to pick the tank. .


Link: [url:1i9vjjl1]http://www.savefile.com/projects/808655567[/url:1i9vjjl1]
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sun Jun 29, 2008 8:43 pm

is this a help for you ?

viewtopic.php?f=3&t=1183
B
3
S
2
G
4
Posts: 322
Reputation: 2,119

Post » Sun Jun 29, 2008 9:05 pm

How exactly are you numbering the tanks? For-Each iterates in order of creation, so maybe your first text object is labelled 8 by accident. Or the text objects were created in the wrong order.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Mon Jun 30, 2008 1:29 am

[code:2ga42qql]Start of Layout
For "MakeTanks" from 1 to 8 + system create object

For each tank + tank: set 'tankid' to loopindex
+ system: create NumberText
+ NumberText: Set text to tank.value('tankid')[/code:2ga42qql]
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Mon Jun 30, 2008 3:12 pm

Try putting the text and the tank in a container together. Always set the position of the text to the tank and set its text to the tankid, and it should use the correct tank.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest