I'm having some difficulty extracting an integer value from a magic token, hope some kind soul can give me a hand.
I'm designing a layout which requires that elements are randomly displayed on the screen when a game is highlighted. I can write a function to determine if a particular element should be displayed or not:
function Getrand()
{
local r = rand() + 1;
r = r % 2;
return r;
}
So this will return 0 or 1, then I'll use this value to hide (if Getrand returns 0) or display (if Getrand returns 1) the element.
Now I need this to update with the navigation, happily magic tokens do exactly that, so I wrote this:
local randVal = "[!Getrand]";
And if I display this value on the screen with:
local showText = fe.add_text(randVal, 900, 870, 0, 0);
It seems to do exactly what I want, the value randomly changing between 0 and 1 as I scroll through the games. So far so good.
Clearly I now need to parse the value as an integer in order to evaluate it, and this is where my meagre coding skills desert me. I innocently assumed that the magic tokens would return as strings, but tointeger() fails every time so something's not right here. All advice (including any entirely different solutions, I'm not proud) would be very welcome, thanks.