Author Topic: Variables in a AM layout  (Read 224 times)

iOtero

  • Sr. Member
  • ****
  • Posts: 349
    • View Profile
Variables in a AM layout
« 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();

I love that on my laptop the eyes shine to the Alien every time i access the ssd... :D

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 960
    • View Profile
Re: Variables in a AM layout
« Reply #1 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.

iOtero

  • Sr. Member
  • ****
  • Posts: 349
    • View Profile
Re: Variables in a AM layout
« Reply #2 on: May 26, 2019, 10:04:38 AM »
Ok, understood. Very well explained.

Thanks, Keil.
I love that on my laptop the eyes shine to the Alien every time i access the ssd... :D