Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: iOtero on June 11, 2018, 08:15:11 AM

Title: Need help to display an array when you press a button.
Post by: iOtero on June 11, 2018, 08:15:11 AM

This code works perfectly:  :D

Code: [Select]
class PlayList
{
show_text=null;

constructor()
{
show_text = fe.add_text("[Title]", flx*0.230, fly*0.001, flw*0.360, flh*0.490);
show_text.visible=false;
show_text.charsize = 20;
fe.add_signal_handler(this, "on_show")
}

function on_show(shw)
{
if (shw == "custom4")
{
show_text.visible=!show_text.visible;
return true;
}
return false;
}
}

local pl = PlayList();


My problem is that i can not get the content of an array[], which contains several data, instead of [Title].  :'(

I tried this (without it working, of course):    :-[

Code: [Select]
class PlayList
{
show_text=null;

constructor()
{
for(local i=0; i<player_list.len(); i++)
{
player_list.push(fe.add_text("", text_x/2, text_y+(i*30), text_wide-text_x, 0));
player_list[i].align = Align.Left;
player_list[i].font = "anaheim";
player_list[i].charsize = font_list_size;
player_list[i].set_rgb(Rp,Gp,Bp);
}

fe.add_signal_handler(this, "on_show")
}

function on_show(shw)
{
if (shw == "custom4")
{
show_text.visible=!show_text.visible;
return true;
}
return false;
}
}

player_list[] is the array in question...
Title: Re: Need help to display an array when you press a button.
Post by: keilmillerjr on June 11, 2018, 09:40:28 AM
Just a quick glance, may or may not resolve your issue. Declare your variable, player_list.
Title: Re: Need help to display an array when you press a button.
Post by: iOtero on June 11, 2018, 01:45:00 PM
Just a quick glance, may or may not resolve your issue. Declare your variable, player_list.

Thanks, but if the array contains data, as I said, it is because previously it is already declared.
Title: Re: Need help to display an array when you press a button.
Post by: iOtero on June 12, 2018, 05:36:20 AM
I have tried with this

Code: [Select]
local mp = MediaPlayer();

class PlayList
{
constructor()
{
for(local i=0; i<player_list.len(); i++)
{
player_list.push(fe.add_text("", text_x, text_y+(i*30), text_wide-text_x, 0));
player_list[i].align = Align.Left;
player_list[i].font = "anaheim";
player_list[i].charsize = font_list_size;
player_list[i].set_rgb(Rp,Gp,Bp);
}
player_list.visible=false;

fe.add_signal_handler(this, "on_show")
}

function on_show(shw)
{
if (shw == "custom4")
{
player_list.visible=!player_list.visible;
return true;
}
return false;
}
}

local pl = PlayList();


And not work...
Title: Re: Need help to display an array when you press a button.
Post by: keilmillerjr on June 12, 2018, 11:57:48 AM
Start simple and test variables as you go. If you write too much at once, debugging boggles your mind with too many things.

You still didn’t declare your player list variable. I like to declare variables before the constructor and assign them in the constructor. Check out my shuffle module and look at the slot variable. It’s an array containing objects and used in a similar fashion as your player_list array.

https://github.com/keilmillerjr/shuffle-module/blob/master/module.nut

You also have another issue. You can’t hide or show visibility of an array. If you want to toggle visibility of all objects within the array, you need to illiterate over the array.

Can you explain what your trying to accomplish with this code? Maybe I could help more.
Title: Re: Need help to display an array when you press a button.
Post by: iOtero on June 12, 2018, 02:01:26 PM
I want to put the contents of an array on the screen when I press a key.
After reading the data of a folder, they are added to an array, and what I want is to put them on the screen by pressing a key, not directly. I guess you have to put the array on a surface or an object, but I'm not very expert.
Title: Re: Need help to display an array when you press a button.
Post by: keilmillerjr on June 12, 2018, 06:11:15 PM
I want to put the contents of an array on the screen when I press a key.
After reading the data of a folder, they are added to an array, and what I want is to put them on the screen by pressing a key, not directly. I guess you have to put the array on a surface or an object, but I'm not very expert.

What is “data in a folder?” It would help me to better help you.

An array is a structured collection of data. You can’t change properties of an array because it isn’t a “gui” object type. You can change the properties of objects stored within the array. Or like you stated, but all the objects in a surface and change the properties of the surface. Use surfaces wisely.
Title: Re: Need help to display an array when you press a button.
Post by: iOtero on June 13, 2018, 06:03:36 AM
Quote
What is “data in a folder?” It would help me to better help you.

Data in the folder "Tom Odell - Long Way Down - 2013":

Quote
01 - Tom Odell - Grow Old With Me.m4a
02 - Tom Odell - Hold Me.m4a
03 - Tom Odell - Another Love.m4a
04 - Tom Odell - I Know.m4a
05 - Tom Odell - Sense.m4a
06 - Tom Odell - Can't Pretend.m4a
07 - Tom Odell - Till I Lost.m4a
08 - Tom Odell - Supposed To Be.m4a
09 - Tom Odell - Long Way Down.m4a
10 - Tom Odell - Sirens.m4a
11 - Tom Odell - I Think It's Going To Rain Today.m4a
12 - Tom Odell - Storms.m4a
13 - Tom Odell - Heal.m4a
14 - Tom Odell - Till I Lost (Demo).m4a
15 - Tom Odell - Grow Old With Me (Demo).m4a
folder.jpg


All files with full tags ID3v2.