Many thanks. So in my previous thread we ended up with this:
function iRand(max) {
// Generate a pseudo-random integer between 0 and max
local roll = (1.0 * math.rand() / RAND_MAX) * (max + 1);
return roll.tointeger();
}
function bRand() {
if (irand(1) == 1) return true;
else return false;
}
function showStopper() {
if (bRand()){
Showelement();
return "On";
}
else {
Hideelement();
return "Off";
}
}
local showText = fe.add_text(„[!showStopper]", 900, 870, 0, 0);
The functions to show and hide the elements look like this:
function showelement(){
local breakup = fe.add_image("staticsprite.png", 1000, 100, blip*0.405, blip*0.2 );
breakup.visible = true;
breakup.trigger = Transition.EndNavigation;
breakup.preserve_aspect_ratio = false;
//sprite animation - use a spritesheet to animate specific frames of the sprite sheet
local sprite_cfg = {
when = When.Always,
width = 462,
height = 200,
frame = 0,
time = 3000,
order = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
loop = true
}
animation.add( SpriteAnimation( breakup, sprite_cfg ) );
}
function hideelement(){
local breakup = fe.add_image("staticsprite.png", 1000, 100, blip*0.405, blip*0.2 );
breakup.visible =false
breakup.trigger = Transition.EndNavigation;
breakup.preserve_aspect_ratio = false;
//sprite animation - use a spritesheet to animate specific frames of the sprite sheet
local sprite_cfg = {
when = When.Always,
width = 462,
height = 200,
frame = 0,
time = 3000,
order = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
loop = true
}
animation.add( SpriteAnimation( breakup, sprite_cfg ) );
}
This approach works initially but AM will crash a few transitions later. OTOH if I have a variable such as myGlobal which I set to 1 or 0 and then do this:
local breakup = fe.add_image("staticsprite.png", 1000, 100, blip*0.405, blip*0.2 );
if (myGlobal == 1) breakup.visible = true;
else breakup.visible = false;
breakup.trigger = Transition.EndNavigation;
breakup.preserve_aspect_ratio = false;
//sprite animation - use a spritesheet to animate specific frames of the sprite sheet
local sprite_cfg = {
when = When.Always,
width = 462,
height = 200,
frame = 0,
time = 3000,
order = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
loop = true
}
animation.add( SpriteAnimation( breakup, sprite_cfg ) );
It works fine, hence my enthusiasm for being able to set variable values using a magic token. Does this make sense now?