how do i create objects without repeating the last position

0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi I know this will be an easy answer for most of you but its giving me grief. I have 5 positions that I want to create an object at but without repeating the last position.

    I have no problem creating the objects but sometimes either with Random or Choose commands they repeat the same position.

    I am having trouble working out how to use the boolean instance to control this.

    If anyone has a capx. that shows me the answer I will be very grateful. I am fairly new to construct 2 and also am 68 years old and having trouble learning some of the aspects.

    Thanks to anyone in advance who can help me. Cheers Robbo128

  • I knocked together a quick example. Hopefully the code is understandable, but keep in mind its probably pretty rubbish. The technique works though.

    Every 2 seconds I generate a random number, which I take the ceil of to round up. I compare that to the LastPlace variable I made, which starts at 0. When they don't match, I go ahead and print the place to a column on the left, then set the last place to that random number. Then I generate another random number and check if they match. If they do, I generate another random number using the same formula, and print a message in the column on the right to show that its working and when a collision has happened.

    I also used a boolean in the sample to show you how to work with it. To check whether its false you have to invert it from the right click menu.

    Now you just need to translate the places into destinations.

    [attachment=0:2r0cul4q][/attachment:2r0cul4q]

  • Hi Saumanahaii thanks for the help I'm being a complete div and cannot work out how to change the places. I have uploaded a capx and perhaps you could have a quick look at it for me. Cheers Robbo128

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • And done. Might have been better to create instances of a single boundary rather than have a new object for each, though. Then you could have used a single event to reference the ID and been done.

  • Hi Thanks for the help but it does not appear to work.

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