INI_WriteString.. How to use it?
#1

I want to add what the user types in a dialogbox, which it stores with inputtext[]

I can't do:
inputtext[0]
inputtext[1]
inputtext[2]
inputtext[3]

etc.
Because there is no defined length for the inputtext[].
Reply
#2

inputtext[0] = first character.
inputtext[1] = second character..

and so on..

A string is basically an array with a number on each of it's data fields, whereas the number is the character in it's ASCI form.

If you want to input the whole string, use it's entire (inputtext):

format(message, sizeof(message),"%s",inputtext);

For example.
Reply
#3

I know what an array is and how it works.. It just confuses me that there isn't a normal string (I'm used to C#).

Right now I've got:

Код:
    			if (strlen(inputtext) == 5)
				{
					new INI:File = INI_Open(UserPath(playerid));
	                INI_SetTag(File,"data");
    	            INI_WriteInt(File,"Password",udb_hash(inputtext));
        	        INI_WriteInt(File,"PasswordLength",strlen(inputtext));
            	    INI_WriteInt(File,"PasswordOne",inputtext[0]);
                	INI_WriteInt(File,"PasswordTwo",inputtext[1]);
   	 				INI_WriteInt(File,"PasswordThree",inputtext[2]);
	                INI_WriteInt(File,"PasswordFour",inputtext[3]);
    	            INI_WriteInt(File,"PasswordFive",inputtext[4]);
        	        INI_WriteInt(File,"Cash",0);
            	    INI_WriteInt(File,"Admin",0);
     				INI_WriteInt(File,"Kills",0);
            	    INI_WriteInt(File,"Deaths",0);
					INI_Close(File);
   				}
				if (strlen(inputtext) == 6)
				{
					new INI:File = INI_Open(UserPath(playerid));
	                INI_SetTag(File,"data");
    	            INI_WriteInt(File,"Password",udb_hash(inputtext));
        	        INI_WriteInt(File,"PasswordLength",strlen(inputtext));
            	    INI_WriteInt(File,"PasswordOne",inputtext[0]);
                	INI_WriteInt(File,"PasswordTwo",inputtext[1]);
   	 				INI_WriteInt(File,"PasswordThree",inputtext[2]);
	                INI_WriteInt(File,"PasswordFour",inputtext[3]);
    	            INI_WriteInt(File,"PasswordFive",inputtext[4]);
    	            INI_WriteInt(File,"PasswordSix",inputtext[5]);
        	        INI_WriteInt(File,"Cash",0);
            	    INI_WriteInt(File,"Admin",0);
     				INI_WriteInt(File,"Kills",0);
            	    INI_WriteInt(File,"Deaths",0);
					INI_Close(File);
				}
For every possible inputtext length, and whilst this works, it's non optimal and I'd rather just input the entire string on 1 line.

Would this work?

INI_WriteString(File,"PasswordFive",format(message , sizeof(message),"%s",inputtext);
Reply
#4

C:\Users\Anthony\Documents\GTA Server\Local Server\gamemodes\TimmehScripting.pwn(865) : error 017: undefined symbol "message"
C:\Users\Anthony\Documents\GTA Server\Local Server\gamemodes\TimmehScripting.pwn(865) : error 017: undefined symbol "message"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Reply
#5

You have to format it Before using it, and define the variable you're storing the formatted data at.

new message[34];
format(message, sizeof(message),"%s",inputtext);
INI_WriteString(File,"PasswordFive",message);
Reply
#6

What's the point of formatting it when you can use it directly?

pawn Код:
INI_WriteString(File,"PasswordFive",inputtext);
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
What's the point of formatting it when you can use it directly?

pawn Код:
INI_WriteString(File,"PasswordFive",inputtext);
Don't really know why he asks because according this code

Код:
INI_WriteInt(File,"Password",udb_hash(inputtext));
he's already doing so.
Reply
#8

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
What's the point of formatting it when you can use it directly?

pawn Код:
INI_WriteString(File,"PasswordFive",inputtext);
I tried that before, and it didn't work.. Now it does work.

I think I might've forgot to change WriteInt to WriteString when I tried it before, which would explain the error.
Thanks both.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)