Picking an object from multiple of same object with keyboard

This forum is currently in read-only mode.
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • 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.

  • Max,

    you forgot to specify the question like ..

    can i do this without rewriting my events in the .cap you will find at

    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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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: http://www.savefile.com/projects/808655567

  • 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!

  • 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: http://www.savefile.com/projects/808655567

  • is this a help for you ?

  • 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.

  • 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]
  • 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.

  • Yo ! max, how r you doing with the game ?

  • Hi TheInstance,

    The game is going fine. I Found out what my problem was with the numbering of my tanks. My coding was fine. It was the Text/Object, I forgot to check the Destroy on start box in the Groups Attributes. So I had 8 tanks and 9 TankNumbers Text/Object. When I did the loop to set the number to the Text/Object things got out of order.

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