Saving inputtext into variable. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving inputtext into variable. (
/showthread.php?tid=280112)
Saving inputtext into variable. -
Homerman - 30.08.2011
Hey.
I've got a problem with saving the inputtext (from OnDialogResponse) into a variable.
This:
Код:
Password[playerid] = inputtext;
Gives me this:
Код:
C:\Users\Viktor\Desktop\SAdmin\filterscripts\SAdmin.pwn(315) : error 006: must be assigned to an array
and this
Код:
if(inputtext == Password[playerid])
gives this
Код:
C:\Users\Viktor\Desktop\SAdmin\filterscripts\SAdmin.pwn(327) : error 033: array must be indexed (variable "inputtext")
I know I have to turn the Password[MAX_PLAYERS] into a variable, but I need to be a variable assigned to current playerid, so I can have two people registering at once... can anybody help me? Thanks.
Re: Saving inputtext into variable. -
AndreT - 30.08.2011
Your variable would need to be defined like this:
pawn Код:
new Password[MAX_PLAYERS][MAX PW LENGTH];
Re: Saving inputtext into variable. -
Homerman - 30.08.2011
Well, I actually got it like that (Password[MAX_PLAYERS][24] - max password length), but how to save the inputtext into the array now?
Re: Saving inputtext into variable. -
AndreT - 30.08.2011
Oh, I'm sorry.
In your case (inputtext length is not defined, hence not the same as the length of the password string), you can use format/strcat/strmid and possibly some more functions. I assume using format would be a simple solution but as far as I know, not as efficient as using strmid in this case.
pawn Код:
strmid(Password[playerid], inputtext, 0, strlen(inputtext));
Comparing strings in PAWN doesn't work as:
You'll need to use the strcmp function (
https://sampwiki.blast.hk/wiki/Strcmp):
pawn Код:
if(!strcmp(Password[playerid], inputtext, false))
Note that the false as the 3rd parameter also checks the input case.
Re: Saving inputtext into variable. -
Homerman - 30.08.2011
Works awesome, thank you!