Author Topic: Put a random icon on the screen.  (Read 1271 times)

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Put a random icon on the screen.
« on: May 17, 2018, 05:30:24 AM »
To put on the screen of my layout a certain icon of the path / icons, I use the following code:

Code: [Select]

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;


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.
« Last Edit: August 15, 2018, 04:25:05 PM by iOtero »

keilmillerjr

  • Hero Member
  • *****
  • Posts: 635
    • View Profile
Re: Put a random icon on the screen.
« Reply #1 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.

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Re: Put a random icon on the screen.
« Reply #2 on: May 17, 2018, 07:50: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.


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

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

Code: [Select]
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;


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".
« Last Edit: May 17, 2018, 08:30:56 AM by zlagos »

keilmillerjr

  • Hero Member
  • *****
  • Posts: 635
    • View Profile
Re: Put a random icon on the screen.
« Reply #3 on: May 17, 2018, 10:21:40 AM »
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.
« Last Edit: May 17, 2018, 10:24:13 AM by keilmillerjr »

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Re: Put a random icon on the screen.
« Reply #4 on: May 17, 2018, 02:54:23 PM »
Solved:

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

Thank you very much.

keilmillerjr

  • Hero Member
  • *****
  • Posts: 635
    • View Profile
Re: Put a random icon on the screen.
« Reply #5 on: May 17, 2018, 05:30:43 PM »
Solved:

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

Thank you very much.

I didn’t test it, but something like this might be easier than numeric file names. Try it and let me know if it works. You can have file names such as „Predator.png“. Include the file extension in the array if they vary, but it’s good practice to have everything uniform if you can.
Code: [Select]
fe.load_module("helpers-module");

local films = [
  "Predator",
  "The Terminator",
  "Total Recall",
]

local film = fe.add_image("posters/films/" + films[randInt(films.len())] + ".png", 0, 0, 0, 0);
film.preserve_aspect_ratio = true;
film.trigger = Transition.EndNavigation;

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Re: Put a random icon on the screen. (SOLVED)
« Reply #6 on: May 20, 2018, 05:59:23 AM »
Thanks, it's a good idea, I'll try it.  :D

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Re: Put a random icon on the screen. (SOLVED)
« Reply #7 on: June 14, 2018, 04:36:41 PM »
The two options work, but both have a small problem: When AM start, the first image is always the same, the others are random, but the one at the beginning, always the same position: 4 in 0-12 or 10 in 0-30.


Many years ago, when ms-dos, I had to do a pseudo-random, and so that it would not happen to me, I took the random seed of the clock: current second.

Sorry for my bad english...  :-[
« Last Edit: June 14, 2018, 04:50:34 PM by zlagos »

keilmillerjr

  • Hero Member
  • *****
  • Posts: 635
    • View Profile
Re: Put a random icon on the screen. (SOLVED)
« Reply #8 on: June 14, 2018, 08:55:49 PM »
The two options work, but both have a small problem: When AM start, the first image is always the same, the others are random, but the one at the beginning, always the same position: 4 in 0-12 or 10 in 0-30.


Many years ago, when ms-dos, I had to do a pseudo-random, and so that it would not happen to me, I took the random seed of the clock: current second.

Sorry for my bad english...  :-[

Your English is great.

The math.rand() squirrel function should deliver pseudo random integers according to electric imp. However, I think how it is generated depends on the processor used.? What’s your platform?

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Re: Put a random icon on the screen. (SOLVED)
« Reply #9 on: June 15, 2018, 04:18:48 AM »
Windows 10 with Intel Core i7-4790K 4.0 Ghz.

qqplayer

  • Sr. Member
  • ****
  • Posts: 247
    • View Profile
Re: Put a random icon on the screen. (SOLVED)
« Reply #10 on: June 15, 2018, 08:58:26 AM »
Another simple solution is put some "random" jpg´s into the "scrapper/[sytem]" folder.
I mean , you have a "NES" layou.nut with something like

fe_add.artwork = icon...

Then just create a folder "scrapper/nes/icon"
Inside 1.jpg , 2.jpg , 3.jpg or wathever you want  :D

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Re: Put a random icon on the screen. (SOLVED)
« Reply #11 on: June 16, 2018, 09:31:28 AM »
Another simple solution is put some "random" jpg´s into the "scrapper/[sytem]" folder.
I mean , you have a "NES" layou.nut with something like

fe_add.artwork = icon...

Then just create a folder "scrapper/nes/icon"
Inside 1.jpg , 2.jpg , 3.jpg or wathever you want  :D

Thanks, a great idea...  :D  but i do not use the scrapper for nothing at all  ::)

qqplayer

  • Sr. Member
  • ****
  • Posts: 247
    • View Profile
Re: Put a random icon on the screen. (SOLVED)
« Reply #12 on: June 16, 2018, 12:38:57 PM »
Another simple solution is put some "random" jpg´s into the "scrapper/[sytem]" folder.
I mean , you have a "NES" layou.nut with something like

fe_add.artwork = icon...

Then just create a folder "scrapper/nes/icon"
Inside 1.jpg , 2.jpg , 3.jpg or wathever you want  :D

Thanks, a great idea...  :D  but i do not use the scrapper for nothing at all  ::)

Don`t need to use it , just create the folder structure and put your media inside :)

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Re: Put a random icon on the screen.
« Reply #13 on: June 17, 2018, 02:14:49 AM »
Well ido not see the difference in what you tell me what I do:

Code: [Select]

local my_film = randInt(30);

my_film = my_film.tostring() + ".png";

local film = fe.add_image("posters/films/" + my_film, 0, 0, flw*0.408, flh*0.6);


Something is slipping away ... :D

(Me lo vas a tener que explicar en español, a ver si así me entero mejor) :)

iOtero

  • Sr. Member
  • ****
  • Posts: 219
    • View Profile
Re: Put a random icon on the screen. (SOLVED)
« Reply #14 on: June 23, 2018, 05:33:09 AM »
The two options work, but both have a small problem: When AM start, the first image is always the same, the others are random, but the one at the beginning, always the same position: 4 in 0-12 or 10 in 0-30.

There is no solution for this bug?