Attract-Mode Support > Themes

Put a random icon on the screen.

(1/4) > >>

iOtero:
To put on the screen of my layout a certain icon of the path / icons, I use the following code:


--- Code: ---
local icon = fe.add_image("icons/icon01.png", flx*0.215, fly*0.025, flw*0.1, flh*0.08);
icon.preserve_aspect_ratio = true;
icon.trigger = Transition.EndNavigation;


--- End code ---

And it works perfectly.
   
But what I want is to put on the screen any of the icons contained in /icons in a random way, that comes out any of those that are inside /icons.

But I do not know how to do it. And I do not find anything either. Somebody could help me?

Sorry for my bad english.

Thanks in advance.

keilmillerjr:
I created a random function.

https://github.com/keilmillerjr/helpers-module/blob/master/readme.md

Pass array length. It return number. Use it as index in array to update image on your transition.

iOtero:

--- Quote from: keilmillerjr on May 17, 2018, 07:07:02 AM ---I created a random function.

https://github.com/keilmillerjr/helpers-module/blob/master/readme.md

Pass array length. It return number. Use it as index in array to update image on your transition.

--- End quote ---


Okay thank you very much.
But, I'm not an expert programmer.

I tried this, but it does not work for me:


--- Code: ---fe.load_module( "module-master" );

// Posters
local my_film = randInt(6);

local film = fe.add_image("posters/films/[my_film].png", 0, 0, flw*0.4, flh*0.3);
film.preserve_aspect_ratio = true;
film.trigger = Transition.EndNavigation;


--- End code ---

Being 1.png, 2.png, etc. my film icons.

And I do not know what I'm doing wrong ... I'm sorry.

Edit:

The module.nut I downloaded it from here:
://github.com/keilmillerjr/helpers-module

I have copied the module "module.nut"  in "E:\arcade\attract\ modules", renaming it "module-master.nut".

keilmillerjr:
Break your string and insert the variable and then continue the string.

Too many languages I do and stressed out at work. Format either “str” . var . “str” or substitute the periods for plus signs.

If you can’t figure it out, I’ll do you up a chunk of code to try - tonight.

iOtero:
Solved:


--- Code: ---local my_film = randInt(6);
my_film = my_film.tostring() + ".png";
local film = fe.add_image("posters/films/" + my_film, 0, 0, 0, 0);

--- End code ---

Thank you very much.

Navigation

[0] Message Index

[#] Next page

Go to full version