Browse Search Popular Register Upload Rules User list Login:
Search:
frustrating asl ngl. (for coders)

Image:
screenshot of the scene

Author: AverageCoder

Group: Default

Filesize: 104.97 kB

Date added: 2024-10-19

Rating: 5

Downloads: 384

Views: 181

Comments: 4

Ratings: 1

Times favored: 1

Made with: Algodoo v2.2.0b

Tags:

Scene tag

A little uhh, expression of discomfort regarding for loops.
Please log in to rate this scene
edit
Similar scenes
Title: Worms.
Rating: 5
Filesize: 28.89 kB
Downloads: 441
Comments: 0
Ratings: 1
Date added: 2017/04/15 07:34:00
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Game
Rating: 5.8333
Filesize: 97.13 kB
Downloads: 143
Comments: 0
Ratings: 6
Date added: 2008/10/10 03:48:24
Made with: Phun
Rating: rated 5.8
download
Title: Algicosathlon Remake Event 4: Sled-Dog Racing
Rating: 5
Filesize: 103.91 kB
Downloads: 773
Comments: 1
Ratings: 1
Date added: 2016/05/14 17:22:56
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: FTTD Update
Rating: 5
Filesize: 0.52 MB
Downloads: 409
Comments: 5
Ratings: 1
Date added: 2018/07/06 06:46:26
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: You Can Still Vote! :)
Rating: 5
Filesize: 73.33 kB
Downloads: 364
Comments: 10
Ratings: 1
Date added: 2015/12/29 02:34:49
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: ACT:Boss 1(Important)
Rating: 5
Filesize: 1.59 MB
Downloads: 357
Comments: 5
Ratings: 1
Date added: 2018/06/30 17:18:51
Made with: Algodoo v2.1.0
Rating: rated 5
download
An old Algobox user known as Kilinich (hope I spelled that right) made a solution!

It's called xfor.
Simply place this script into any object and name it _xfor:

(n1, n2, code)=>{
n2 > n1 ? {
m := (n1 + n2) / 2;
_xfor(n1, m, code);
_xfor(m + 1, n2, code)
} : {code(n1)}
}

and you're done!

Xfor loops from n1 to n2 whilst running the given code.
It still has a recursion limit, but it's almost infinite! The difference is that regular for spawns new scripts linearly (i.e. every "for" can only spawn one other "for") whereas xfor spawns new scripts exponentially (i.e. every "xfor" can spawn 2 more "xfors").

If the recursion limit was just 4, then xfor would be able to run for 2^4 = 16 iterations, while for would only be able to run for 4!

Assuming a clear stack with a recursion limit of 64, xfor would be able to run for 18 quintillion iterations, while for could only run for a puny 64! :o

Very deep recursion aside, xfor's iteration limit is so high that running into it would take a very, very long time. :lol:

I hope this helps! Xfor has saved me so, so much pain. _o_

There is a catch though unfortunatey. :(
Xfor is slightly slower than for, and for what reason I'm not sure. It shouldn't be too bad though! :lol:

I wish you luck! :lol:
If you need any more scripting help in the future, I might be able to help! -- I will subscribe to this scene so I get notified if you comment on it again.

(Is doing that allowed Xray?) :huh:

(Also keep in mind that I'm not very smart, soo...... :bonk:
My code usually works but it also usually runs about as efficiently as blowing on a truck to move it)
Last edited at 2024/10/19 07:51:04 by Little
By the way, your drawing is really nice! :)
Little -- Here's a little detail (pun intended) that may be helpful in some situations. If you only need to use the Xfor function inside one object, then creating it as a local function (using the underscore character) is perfectly Okay. But if you may need to use the Xfor function in multiple objects, then save it as a global (scene.my) function. That way you can call it from any object without needing to duplicate the code for each object. Put the following code in the console:

scene.my.xFor := (n1, n2, code) => {
n2 > n1 ? {
m := (n1 + n2) / 2;
scene.my.xFor(n1, m, code);
scene.my.xFor(m + 1, n2, code)
} : {code(n1)}
}

Then to call it from any object simply use: scene.my.Xfor(arg1,arg2,arg3)
Little -- Concerning your question "Is doing that allowed Xray?". YES! This is the kind of thing that comments were meant for. :)