Page 1 of 1

keypad help [SOLVED]

Posted: August 23rd, 2011, 10:04 am
by Goro92
i made a working keypad but i want to add a button that delete the last number added..
i make an example because of my english....if i put this code 12345663--->hit the CancKey--->the code now is 1234566


i tried this but not work

Code: Select all

 
main()
{
....
 
thread ButtonCANC();
level.scritta = ""; 
}
 
.....
ButtonCANC()
{
buttonCANC = getent("buttonCANC","targetname");
while(1)
{
buttonCANC waittill ("trigger", user);
level.scritta = level.scritta - " ";
user iprintln(level.scritta);
wait .5;
}
} 
 

Re: keypad help

Posted: August 23rd, 2011, 10:51 am
by iCYsoldier
Maybe try: create a temp string; set it to the users code without the last char by looping through the string; set the current code to the temp string

There might be a more efficient way of doing this, but I just thought of this

Re: keypad help

Posted: August 23rd, 2011, 10:55 am
by Goro92
iCYsoldier wrote:Maybe try: create a temp string; set it to the users code without the last char by looping through the string; set the current code to the temp string

There might be a more efficient way of doing this, but I just thought of this
wait wait wait...i'm not so pro in script XD

how to create a temp string?

thx for help

Re: keypad help

Posted: August 23rd, 2011, 11:43 am
by IzNoGoD

Code: Select all

if(level.scritta.size>0)
level.scritta = getsubstr(level.scritta,0,level.scritta.size);

Re: keypad help

Posted: August 23rd, 2011, 12:45 pm
by Goro92
IzNoGoD wrote:

Code: Select all

if(level.scritta.size>0)
level.scritta = getsubstr(level.scritta,0,level.scritta.size);

Code: Select all

main()

{

....

thread ButtonCANC();

level.scritta = "";

}

 

.....

ButtonCANC()

{

buttonCANC = getent("buttonCANC","targetname");

while(1)

{

buttonCANC waittill ("trigger", user);

if(level.scritta.size>0){
level.scritta = getsubstr(level.scritta,0,level.scritta.size);

}

user iprintln(level.scritta);

wait .5;

}

} 

there is no error but does not work...just repeat the code without delete the last number added..
maybe there is something that i need to add in the main?

btw thx for ur help

Re: keypad help

Posted: August 23rd, 2011, 1:10 pm
by IzNoGoD
Damn, i must have been sleeping somehow
getsubstr(level.scritta,0,level.scritta.size-1) ofc

Re: keypad help [SOLVED]

Posted: August 23rd, 2011, 1:25 pm
by Goro92
IzNoGoD wrote:Damn, i must have been sleeping somehow
getsubstr(level.scritta,0,level.scritta.size-1) ofc

PERFECT! :mrgreen:

THANKS!