Trouble with accessing variables from clones

Hi! I'm trying to create a racing game that will be multi-player (on the same computer, of course, I don't understand any of the fancy Javascript cloud variable things.)
I am going to explain what the circumstance is so the problem may be easier to solve.
I have a master sprite. The players will be clones of this sprite. I have some "for this sprite only" variables, those being car.x, car.y, caracc (car acceleration), car.turnacc (car turn acceleration), and car.checkpoints, which is the one I'm having a problem with. The game has a 2d list of values for checkpoints, those being x coords, y coords, and directions. Clones are created of the checkpoint sprite and go to these coordinates and those directions. The idea is they check for the clones of the master copy of the car, see if they are touching them, and then check their "car.checkpoints" value. Each checkpoint clone is numbered, and if the car's checkpoint value is one less than the checkpoint's ID, it changes the car.checkpoint value by one. This way, the player has to hit these checkpoints in a specific order. Additionally, these checkpoints are invisible, because they are only there to prevent the player from going off-track and doing loops around the starting line for easy laps. The problem is, for the life of me, I cannot figure out how to get these checkpoint clones to access the value of this variable. The checkpoints don't have a variable called "car.checkpoint", so I have no clue what to insert. I've looked through both the "ask" block and the "_ of _" block, to no avail. Could someone explain what I need to do?

Also, sorry for it being kinda long XD

Don't be sorry, long questions are always better, because they (should) contain all the information needed for someone to help.


How did you try the ([] of []) block? That should work.

Here's a script that might work.

Here's what it does.

  • It starts by getting the clones that the checkpoint is touching.
  • It loops through all the touching clones and checks for if the checkpoint id is 1 more than the car checkpoint variable. To get the "checkpoint" in the first slot, set the second slot to the car sprite, then select the "checkpoint" variable, then put the "car" variable into the second slot.
  • In order to set the "checkpoint" variable of the clone, you need to tell the clone to set the variable. To get the "checkpoint" variable in the slot, you have two options. Pass the "checkpoint" string into the function using the "with inputs", or go into the car sprite, pull out a "set variable" block, select "checkpoint", then drag that onto the checkpoint sprite. That will send the block to the checkpoint block, which you can then using in a "tell" block.

Personally I would put the checkpoint system into the cars themselves. Instead of having the checkpoints check if they're touching a car, have the car check if they're touching the checkpoint, then just change the variable. This would look something like this.

This script handles touching more than one checkpoint at the same time, and it doesn't have to tell another sprite to do something. I'd say this is a much better way of handling a checkpoint system.

I thought about putting the checkpoint stuff in the cars instead of the checkpoints, but the problem is that the checkpoints are hidden, and if I remember correctly, the "touching" block won't work if it's hidden.

Also, you can put a variable in that first slot to find a value? How? When I looked, I was unable to get a variable value of a clone in there, only normal stuff, like position, direction, etc.

  1. Select a parent sprite from the drop-down
  2. Select a sprite-local variable name
    untitled script pic - 2024-06-08T025046.924
  3. Insert an actual clone reference to the second slot

OR

untitled script pic - 2024-06-08T024848.179

If the sprite is hidden yes, but you can set ghost effect to 100, and the checkpoint will be hidden visually, but still be able to interact with the <is [] touching [] ?> block.

If you select the main sprite in the second input, you can get sprite only variables at the bottom of the first input.