Page 1 of 1

Variables and Algobox

PostPosted: Sat Mar 16, 2019 7:05 pm
by TShrepel85
Hello again! My pinball project is turning out to be much more difficult than I anticipated. The problem I'm facing now is loading it onto the Algobox for other people to enjoy. I used a TON of variables to make things happen that I hoped would emulate a true pinball experience (e.g. multiball, extra balls, skill shot timers, fade distance of lasers changing when a target is hit, etc.). Now, many of my variables are inserted into object's properties like fadedist, colorHSVA, collideset. When I run the scene on the laptop I created it in, everything works fine. As soon as I download it on another computer, almost everything is broken.

In researching on the forums, I found a post (viewtopic.php?f=13&t=11041&p=79206&hilit=gearbox&sid=756efde8eae66af26a73fb879f7b1002#p79206) that mentioned declaring variables used in the onspawn event. Tried this and it didn't work, tried using ":=" and "=" when declaring them, neither one worked. Is there something I'm missing? Do I need to declare my variables a different way? I'm getting really frustrated with Thyme, and I don't really understand much about it in the first place, kinda learning as I go.

Thank you all for your help, looking forward to a revolutionary response!

Re: Variables and Algobox

PostPosted: Sat Mar 16, 2019 7:31 pm
by FRA32
To declare variables in objects, use the object-console in the top left of the script menu(the empty, black box).
There, enter _varName = 0. Replace the name with whatever you like, as long as you keep the underscore. Doing so will forcefully create a permanent variable in the script menu that is only accessible by the object it belongs to.

Global variables can be made the same way, but instead of _name, you use scene.my.name (once again replace the "name" with your name, but keep the Scene.my.). They can be used by all scripts in the scene.

Once you created the variables you want to use, actually using them is as simple as changing density or sim.gravityStrength. No := required or anything (:= is used when forcefully creating new variables, for example when using scene.addCircle({timetolive := 5}));

Re: Variables and Algobox

PostPosted: Thu Mar 21, 2019 2:51 pm
by TShrepel85
I've tried this with no success, especially on my recently redone high score list. The function I declared in the high score box went into the Algobox, but the main array that holds the scores is "undefined." Most of my other variables are also "undefined" and the problem with that is I use a lot of them in text fields or as fade distance for lasers. This means they revert to their default settings and I've got lasers all over the place and blank boxes where I expect to see a readout. I'll attach my scene file for your review.

Re: Variables and Algobox

PostPosted: Fri Mar 22, 2019 10:49 pm
by FRA32
You can't just type "points" or similar to access a variable. If it's a global variable(scene.my.varthing) then you always have to access it that way:

text = ""+scene.my.points for example.

In the same way, private variables are always accessed with _varthing.

angle = 5*_speed/sim.frequency

scene.my. is the scene's repository for custom variables, any variable created there must be accessed from there aswell, which is why scene.my must always preceed the global variables name!

Re: Variables and Algobox

PostPosted: Sat Mar 23, 2019 6:37 pm
by Ken3344
Hey TShrepel85! I saw your pinball thing, and it was really cool. Could this be an uploading problem? I think that is the only explanation for this. :)