How to tell another clones state?


#1

So I’m making a sort of circuitry game made out of a grid of squares(300 and something clones). I need one clone to be able to tell if another clone has been turned on or off… is this possible?


#2

Maybe when one clone is turned off it sets a variable to, say, 1, and the next clone, the one you want to move when the other one turns off, has a

When Variable = 1
(Insert what you want the object to do here)

That’s the best I’ve got. I know @Petrichor has some useful tutorials.
Hope this helps, and welcome to the forum!


#3

It depends on what you need. This project assumes only 1 will change state at a time, and all the objects are clones of each other.




The first block here sets state to 1. The second block sets the clone index of the object you want the message to Be sent to. The third block, the ability will be explained later. The blocks after that are what is done when self state = 1.

(By the way this project has 380 clones, that will become important a little later)



Here is the ability. As you can see, it’s just a set variable block. Let’s look at that math a bit closer.

What’s the largest operator? That addition. One of the bubbles is state, the other contains a multiplication. The multiplication contains the variable selecting which clone to send the message to. It also contains a power. In this power, the first bubble will always equal ten. The second bubble will be the amount of digits in you largest clone index. So for less than a thousand clones, but more than 99, it’ll be 3.
This math means that the variable will be set to the index of target followed by the state. So if index of target = 100 and state = 1, it will be 1001.
But how do the clones receive this information correctly?



Here we have a conditional. If (math I will explain later) = self clone index.
What’s the largest math operator? Round. What’s in it? Subtraction. The second bubble will always equal 0.5. This means that any number greater than zero that is inside the first subtraction bubble will be rounded down. This allows for states greater than 4 to be correctly received by the proper clone.
The first bubble contains a division. State change / the same power in the variable.
Going back to our example, of 100 as the target and 1 as the state, with 1001 as the variable, this division gets us 100.1. When we round it down, we get 100. The target.
So this says when target clone index = self clone index, do something. I have it so the custom ability from before, but you will have it do something else using the state. Make sure to save the state. How? Take the division from the when, and put it in the first bubble of a substraction. Then take the entire when, and put it in the second bubble.
Wrap that subtraction in a multiplication, and put the power we used in the other multiplication.
This will get you the state.



Hope this helps!


Edit: just realized that this code doesn’t allow for states greater than nine. Is that a problem?


#4

Hi @Petrichor
I like your example but using encoding/decoding for a 1-at-a-time push or pull communication between clones is way over complicating the task.

Setting 2 global variables of State & Target_Index, the state can be passed with

When 📱Target_Index = (self) Clone Index
    Set (self) State to 📱State

#5

@paran0id
A circuit emulation project sounds cool. I’ve wanted to do that for a while but never got around to it.

The short answer is, no, clones can not directly reference the traits or object variables of other clones. @Ana This is a shame as it’s a significant limitation of Hopscotch and is a roadblock to innovation & creativity.

The longer answer is with enough complexity you can get close. Data can be passed in a one-at-a-time fashion as discussed above, but with 300 clones, it’d take at least 5 seconds (300/60fps) just for each clone to pass/receive data to/from 1 other clone.

To pass data more quickly, the data has to be encoded/decoded onto a global variable. This would be similar to @Petrichor’s example but with a different encoding. Since a Hopscotch variable has 16 digits of precision, and you were wanting to pass Boolean data (on/off states), we can use this encoding
image
to encode 53 states into one global variable (since 2^53 is a 16 digit number). But with 300 clones this would still require 6 variables and quickly decoding the values would require tedious amounts of code.


#6

I’ll test this out when I get home. Cheers for putting in so much work, I got some nice things planned


#7

@Petrichor @paran0id @CreationsOfaNoob

I just realized that decimal to binary conversion is possible in a single frame on an individual object basis, and even better, is easy to code using nested custom rules!

This means it IS possible for clones to set & read a state property of other clones all concurrently with just 1 frame of delay.

The possible draw back is that the technique of using nested custom rules created a huge number of rules, so it may slow the FPS. (Edit: I just tested with over 3400 rules and the FPS was unimpacted)

This is very exciting as it will allow projects that were not previously possible! Stay tuned. I’ll make a demonstration project & detailed explanation.


#8

Sounds cool! Thanks for the update.


#9

My demonstration project (an over complicated effort that’s trying to allow 1000 clones to synchronously communicate states) has a bug that I’m struggling to find without a way to step through the executing code :persevere:. I’ll find & fix it. Eventually.


#10

@Petrichor @paran0id @CreationsOfaNoob
An example project demonstrating simultaneous (within 1 frame) communication between 1000 clones is linked in this topic: