Variables and Algobox

About advanced scenes, and the Thyme scripting language used in Algodoo.

Variables and Algobox

Postby TShrepel85 » Sat Mar 16, 2019 7:05 pm

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!
TShrepel85
 
Posts: 7
Joined: Mon Mar 04, 2019 9:00 pm

Re: Variables and Algobox

Postby FRA32 » Sat Mar 16, 2019 7:31 pm

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}));
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm

Re: Variables and Algobox

Postby TShrepel85 » Thu Mar 21, 2019 2:51 pm

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.
Attachments
Pinball 1.10.phz
(700.9 KiB) Downloaded 257 times
TShrepel85
 
Posts: 7
Joined: Mon Mar 04, 2019 9:00 pm

Re: Variables and Algobox

Postby FRA32 » Fri Mar 22, 2019 10:49 pm

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!
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm

Re: Variables and Algobox

Postby Ken3344 » Sat Mar 23, 2019 6:37 pm

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. :)
Hello my name is Kenlimepie. I'm an Algodoo Enthusiast, and Marble Racer. I run a Youtube channel which is about Algodoo Marble Racing, but I am not afraid to design new ideas in this program. https://www.youtube.com/c/kenlimepie
Ken3344
 
Posts: 53
Joined: Mon Sep 05, 2016 8:44 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 2 guests