TBSr's General Hopscotch Coding Topic


#265

I believe for eventParameters you can do a search for each of the ID's, and if it doesn't appear anywhere else in the file then it's unused and should be deleted. There are usually hundreds of eventParameters, so it will take you a long time manually unless you use a computer program. Not sure about traits, though. I couldn't find a way to tell if a given trait is being used or not.


#266

@t1_hopscotch
Moving the code to new events is a good idea. I hadn't tried that. That's a good solution if there aren't too many events. However, just be aware that the json file will continue to grow until eventually it won't upload to the server. Most projects wouldn't get that far though.

All of the eventParameters can be deleted, but you'll have to fill out the bubbles with the object reference afterwards. The program I made checks both eventParameters & traits and only deletes them if they're not being used.

I haven't been able to keep up with a couple requests to fix projects recently so I think I'm going to make a topic and get everyone the exe. (I was waiting to see if I'd have time to add functionality to download & upload the projects from the GUI instead of having to go through iTunes. Haven't had time yet though. And haven't asked THT if that'd be ok)


#267

How do you tell if a trait is being used?


#268

Each trait was a unique HSTraitIDKey in the same way that each eventParameter has a unique id. I search those values to see if they're referenced anywhere else in the project. Then delete the corresponding traits array element if it's not.


#269

@Themasterofairjitzu @NindroidGames
I saw you had a project that needed the json data fixed, but took the link down. I should have time today if you still need the project repaired, but I need the link again.


#270

Ok, because I'm not gonna have time to code more in it. One second.


#271

Ok, @NindroidGames, I have it saved as a draft. I'll fix it for you when I'm by my pc later today.


#272

@MR.GAM3R and @ThinBuffalo wow this explains a lot for me, thanks so much again!!


#273

Hi ThinBuffalo :smiley: I saw your project on arrays in Hopscotch. funnily, recently I was thinking about implementing arrays in Hopscotch using this sort of idea:

where you would be able to specify an index to set a value in the array, and another index to access a value in the array (you would be able to access the value implicitly from a global variable). and I had the idea that this could be used for multiple arrays in a project at once, using the same set of clones.

Then I saw your project :smiley: you did it in a simpler way than what I put above :smile:

I realised though, that I was trying something out which needed multiple objects to be accessing the array at the same time, and that this technique wouldn't work because there's only one global setter/getter variable :thinking: hmm I can't really think of any ideas around it at the moment.


#274

Hi @t1_hopscotch, just to frame the discussion, which project were you looking at? Array using clones or array using encoding into a single value?


Or

Edit:
I assume the former & I think you were referring to this?

In hind sight, I should have done it like this so it fully executes in "1 frame":

But yeah, only one set or read "request" would be handled per frame. And multiple external objects writing to the Array Index or Array Value, during the same frame, would overwrite each other with the Array object only "seeing" one set of the values.


#275

Got it.


#276

@t1_hopscotch I had another thought to add to the discussion about arrays. Creating an array using the encoding/decoding method (2nd project above) does allow for concurrent read/writes to different array "elements" since the encoding effectively multiplexes the array access. I've used that in several projects (like Control Tower WIP).

The downside is the number of elements and value's ranges are limited by the maximum precision of numbers in Hopscotch. Ie, if you wanted an array of booleans you could have more elements than an array of 2 digit integers (and of course the encoding is tailored to each case). I made a topic on this subject a while back. The precision of Hopscotch numbers has increased since I made the project & topic, but I haven't re-investigated the find the new limits.


#277

Ooh yeah I was looking at the first project, I don't think I've seen the second one yet so I will take a look :smiley: And that is really interesting, getting it to calculate in a frame! :open_mouth:

I am thinking about using an array for calculating factorials and I have multiple clones accessing the array at once.

(Basic idea)

array[0] = 1
array[1] = 1

factorial(x):
    If x is in array
        Return array[x]
    Else
        Set array[x] to x * array[x - 1]
        Return array[x]

Previously I was using iteration to calculate factorial, which I think takes O(n) time and I wanted to try do it more quickly.

I think I don't understand much of what you said about the downside of the second method but I haven't seen it yet so I will take a look first :relaxed: Thank you so much again :smile:


#278

Oh, I see. Interesting :thinking:... a factorial can be calculated in 1 frame (or at least in one "step") instead of O(n), if you have n clones to perform the calculation...

Check out this project. It finds the clone with the largest value in 1 iteration instead of O(n) as a naive implementation would do to iterate through the entire collection. The project has remarks in the code to offer some explanation, but I'll let you discover how it works (or more precisely how Hopscotch works in this regard).

After reviewing the project: Do you see how to exploit Hopscotch code execution timing for calculating factorials? :smiley: Hit me up with any questions.

P.S. It's this same understanding of code execution timing that explains how the exponential "fast clone creation" works...


#279

@t1_hopscotch
Only if you want to check your optimization:
I tested and with n clones, factorials can be calculated with 1 event & 2 blocks.


#280

Woah that is really cool...

So this Check Once If runs at the same time for all the clones


I can understand the initial ties – the numbers that go red – but I think I'm a bit confused on how the final Max value is reached.

Thank you again. I'm not sure how to apply this for calculating factorial :thinking: (I've got hundreds of clones that need to calculate factorial, several times, all around the same time :thinking:) Using an array with the basic idea I put earlier, it would end up taking O(1) time with how the project is set up

Wait... So I definitely have enough clones to do the calculation :slight_smile: hmmm I am going to keep thinking about it (no answers yet :slight_smile: )


#281

Whoops I'd started replying before I saw your last post, woah that's neat :open_mouth:


#282

The Check If and Set Max do, in fact, iterate sequentially through the entire collection of clones. As collection is iterated, each clone/value that set a new max thinks it had the max value (those that turned red). So a 2nd Check is required (to recheck those values compared to the final value of Max) to get only the clone with the true max value to respond (turn green)

After I tested calculating factorials, this project is more complicated than required to calculate the factorials. It's just the understanding of the code execution timing (the fact that all clones are executing the block of each frame in series) that I wanted to highlight.

Factorial calculation is more like the 1st array project from above where only one object can access the array (or function in this case) at a time. Even precalculating the factorial results and putting those results into an array where element(n) holds the value of factorial(n) would still yield the same one-at-a-time access result.

The 2nd method can't be used since the factorial result has too many digits to be multiplexed.

What's the largest n that you need to calculate factorial of? And how many is "hundreds of clones"? I've one more thought that might allow for concurrent factorial calculation, but only if n x Number_of_clones < 4096 - Number_of_clones


#283

Ohh okay thank you, I see :relaxed:


Hmm for the project I went extreme and put 63*63 clones just to try that out... :grin:, which aren't all calculating at the start but they eventually do. i realised the frame rate slowed down anyway to around ~8-10 FPS with that many clones, it seemed.

I don't know if background information helps

I am using factorial for calculating combinations, to work out numbers in Pascal's triangle

At the moment, for each clone, I am using the combinations formula:

I wanted to make calculating factorials more efficient here – it's repeating n+1 times and n increases for each row of Pascal's triangle. Potentially it could go on forever but we could arbitrarily pick a number to stop at, similarly with the number of clones (I can set it to any number)
The whole project slows down with more clones anyway so I think that's the bigger thing for me to look at than a quicker factorial algorithm hmm...

There are probably better ways to do all this, but this was the way I'd thought of.

Don't worry about this though, I was just curious about arrays while thinking through this :blush:


#284

@t1_hopscotch I only had a minute or two to look at your project. Are you trying to use Pascal's Triangle to draw a Sierpinski Triangle? Just curious to understand the intended end result and black/yellow pixels.