How do I prevent two of the same sprites from having the same value?

0 favourites
  • 4 posts
From the Asset Store
Antisuspend Plugin for Construct 3 prevents the runtime from getting suspended.
  • Hi, I am currently making an F-Zero fangame (a racing game) and am having issues with creating the final position system (finding out whether a racer finished 1st, 2nd, 8th, etc.)

    I've had little issues with getting the player's position to work. I've created this code that triggers when the player crosses the finish line, and it basically counts how many Racers have finished the race in order to determine the player's final positon)

    (Some things to note: The "Racers" family only contains the PlayerMachine and CPU sprites, and "Final_Position" is a family variable. Also the code below continues in the exact same way up until CPU.PickedCount = 14, because this game has 15 racers.)

    I've tried using this same system for the CPUs, although I have to make it using the Racers family rather than just the CPUs, as the CPUs are competing against both each other and the player of course. I also want to implement a system where the boolean variable "FinishedRace" (which is also a "Racers" family variable) becomes true once the player reaches the finish line, making the CPU's final position whatever their current position (CurrentPositon) was in the race.

    But this system has proved to be very glitchy and unreliable with the CPUs. The main problem I'm running into is multiple racers having the same position at the end of the race. The most common one is both a CPU and the player ending with the same Final_Positon, but sometimes multiple CPUs have the same Final_Position as well. My guess as to why this happens for the CPUs is because of this set of code that makes the CPU's final position whatever their current position is when the player crosses the finish line, as mentioned earlier.

    I've been trying to find a way to have two instances of the same sprite compare each other, like having something like:

    If Racers.Final_Position = Racers.Final_Position, then add 1 to Racers.Final_Position

    But obviously that code wouldn't work, as Construct doesn't allow you to compare two of the same families in that way.

    Sorry if I'm not clear about something, but if any of you all could help it would be greatly appreciated! These CPU position bugs have been plaguing my game for a while now

  • Delete most of this, create a global variable for position set to 1 by default, then say when Racer crosses the finishing line (lap > 4 ?), set finishing position to global variable and add 1 to global variable. If needed you can also use a condition 'final position = 0' to act as your trigger once, it will only set a position value when it is the default.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Delete most of this, create a global variable for position set to 1 by default, then say when Racer crosses the finishing line (lap > 4 ?), set finishing position to global variable and add 1 to global variable. If needed you can also use a condition 'final position = 0' to act as your trigger once, it will only set a position value when it is the default.

    Thank you, I can see how this would work mathematically. Although I am having issues with it.

    I did some debugging and found that PositionCalc (the global variable you told me to make) always ends at 4 at the end of the race for some reason. There seems to be an issue with how the variable gets increased

    ^ How the CPUs get PositionCalc added

    ^ How the Player's PositionCalc gets added

    ^ How the CPUs (the ones who haven't finished the race yet) get their PositionCalc added (should I do it like this? Or should I go back to the original "set Final_Position to Current_Position for these CPUs? Because I'm not sure)

    Anyways I'm still pretty stumped on this, if you or anyone else could help me out still that would be great

  • I expected you to do it with Racers family that includes player and cpu, that will reduce risk of bugs. Also you should drop the trigger once and use the variable as the condition as mentioned above, either position=0 or finishedrace=false will do. Should be one easy line/event for everything.

    Does it stop at 4 when the player finishes and 2 CPU? It is always 4 ? Make the single event as I described with the fam and you won't have to track so many increases to the variable. The results screen is new, you can add debugging to find out if that does anything, maybe the picking is off. Reduce opacity of Racers that are finished to clearly determine who has finished and compare with the variable, do they match, and do this without the results screen first to find the cause.

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