Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: dark1973 on November 12, 2018, 02:05:27 AM

Title: help to find letter postion
Post by: dark1973 on November 12, 2018, 02:05:27 AM
Hi. i need help regarding this code:

local charlist = [ "a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0"];

//return the first letter of the game
function firstletter()
 {
        local pstrip = fe.game_info(Info.Title).slice(0,1);
        return pstrip;
 }

//return the index position of letter game
function findchar()
 {
   local pstrip = fe.game_info(Info.Title).slice(0,1);
        foreach (index, item in charlist)  {
  if (item == pstrip)  {
    return index;
  }
}
 }

local lettera = fe.add_text( "[!firstletter] ", 25+[!findchar], 25, 70, 35 );

i have an error "null 0x000"returnig the value index.

...if (item == "d").... in this case index value is "3" correct

 My goal is to create an alphabet bar with char select. Please Help
Title: Re: help to find letter postion
Post by: dark1973 on November 12, 2018, 04:58:18 AM
function firstletter()
 {
        local pstrip = fe.game_info(Info.Title).slice(0,1);
        return pstrip;
 }
function findchar()
 {
   foreach (index, item in charlist)
{
  if (item.tostring() == fe.game_info(Info.Title).slice(0,1))  {
   
posizione = (index+1)*10;
return (index+1)*10;
  }
else {}   
}

posizione = 130
return 130;
 }
 
posizione = findchar();
local lettera = fe.add_text( "[!firstletter] [!findchar]", posizione ,10 , 100, 35 );

now position of char work correctly.
integer posizione not refresh. Help please
Title: Re: help to find letter postion
Post by: keilmillerjr on November 12, 2018, 05:35:26 AM
Could you just use find(value) to return the array index?
Title: Re: help to find letter postion
Post by: dark1973 on November 12, 2018, 06:05:18 AM
now problem is posizione refresh  :'(
Layout with text refresh only when load first time.
Title: Re: help to find letter postion
Post by: dark1973 on November 12, 2018, 06:38:29 AM
Could you just use find(value) to return the array index?

charlist.find(fe.game_info(Info.Title).slice(0,1))+1)*20   this way?

Unfortunately, when I change games, position is not updated
Title: Re: help to find letter postion
Post by: dark1973 on November 12, 2018, 06:45:27 AM
function transition( ttype, var, transition_time )
{
   if ( ttype == Transition.?????????) {
...
...
....
   }
   return false
}
fe.add_transition_callback(this, "on_transition")

this way?
Title: Re: help to find letter postion
Post by: keilmillerjr on November 12, 2018, 08:40:39 AM
Could you just use find(value) to return the array index?

charlist.find(fe.game_info(Info.Title).slice(0,1))+1)*20   this way?

Unfortunately, when I change games, position is not updated

Do it inside your magic function instead of your foreach loop and compare line. Both do the same thing. Just trying to clean up code. :)