Author Topic: help to find letter postion  (Read 158 times)

dark1973

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
help to find letter postion
« 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
« Last Edit: November 12, 2018, 06:54:01 AM by dark1973 »

dark1973

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: help to find letter postion
« Reply #1 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
« Last Edit: November 12, 2018, 05:01:22 AM by dark1973 »

keilmillerjr

  • Hero Member
  • *****
  • Posts: 638
    • View Profile
Re: help to find letter postion
« Reply #2 on: November 12, 2018, 05:35:26 AM »
Could you just use find(value) to return the array index?

dark1973

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: help to find letter postion
« Reply #3 on: November 12, 2018, 06:05:18 AM »
now problem is posizione refresh  :'(
Layout with text refresh only when load first time.
« Last Edit: November 12, 2018, 06:12:34 AM by dark1973 »

dark1973

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: help to find letter postion
« Reply #4 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

dark1973

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: help to find letter postion
« Reply #5 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?

keilmillerjr

  • Hero Member
  • *****
  • Posts: 638
    • View Profile
Re: help to find letter postion
« Reply #6 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. :)