Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: iOtero on May 26, 2019, 04:17:13 AM

Title: Variables in a AM layout
Post by: iOtero on May 26, 2019, 04:17:13 AM
In a AM layout, what difference is there between using this:

Code: [Select]
my_time <- 0;
try {my_time = my_config["_msgs"].tointeger();} catch(e) {}

or use this:

Code: [Select]
local my_time = my_config["_msgs"].tointeger();

Title: Re: Variables in a AM layout
Post by: keilmillerjr on May 26, 2019, 04:35:09 AM
Code: [Select]
my_time <- 0;
try {my_time = my_config["_msgs"].tointeger();} catch(e) {}

You are declaring a global variable my_time of the value 0. Trying to store another value, converting to integer, into my_time. Catch error should that expression fail.

Code: [Select]
local my_time = my_config["_msgs"].tointeger();

Declare a local variable my_time the value of another value, converting to integer.

I understand what you are trying to do. Use a local value inside a try/catch block. When you catch the error, print to console and set a default value. This is what I do. Or screw em. Depends on how much „fail proofing“ you want to do. I try to assume that the users are dumb as a door knob. With rpi „images“ being a thing now, my attitude is pretty spot on with results.
Title: Re: Variables in a AM layout
Post by: iOtero on May 26, 2019, 10:04:38 AM
Ok, understood. Very well explained.

Thanks, Keil.