How to store inputtext into variable properly?
#1

Hello there,
I'm trying to save inputtext into a variable but does not work.
I did try the following: but all ways saved the variable info as 0
What am i doing wrong?

Way 1:
Код:
ShowPlayerDialog(playerid,TUT4,DIALOG_STYLE_INPUT,"Character creation","{FFFFFF}Enter your characters first name. eg. John or Sara","Next","");
if(dialogid==TUT4)
	{
  		if(response)
		{
			INI_Set(Acc(playerid),"CharacterFirstname",inputtext);
}
}
Way 2:
Код:
ShowPlayerDialog(playerid,TUT4,DIALOG_STYLE_INPUT,"Character creation","{FFFFFF}Enter your characters first name. eg. John or Sara","Next","");
if(dialogid==TUT4)
	{
  		if(response)
		{
			CharacterFirstname[playerid] = inputtext;
}
}
Way 2:
Код:
ShowPlayerDialog(playerid,TUT4,DIALOG_STYLE_INPUT,"Character creation","{FFFFFF}Enter your characters first name. eg. John or Sara","Next","");
if(dialogid==TUT4)
	{
  		if(response)
		{
new value = strval(inputtext);
			CharacterFirstname[playerid] = value;
}
}
What am i doing wrong?
Reply
#2

Show your init for CharacterFirstname
Reply
#3

Quote:

new str1[256];
format(str1,sizeof(str1),"%s",inputtext);


INI_WriteString(File, "CharacterFirstname",str1);

the last line is separated.
Reply
#4

Quote:
Originally Posted by Isolated
Посмотреть сообщение
Show your init for CharacterFirstname
new CharacterFirstname[MAX_PLAYERS];
Reply
#5

You must declare it as array, eg:

Код:
#define MAX_FIRSTNAME 20
new CharacterFirstname[MAX_PLAYERS][MAX_FIRSTNAME];
(The define holds the maximum length of the first name, optional but useful to check for input length etc).

Later, you can insert inputtext to the array like this:

Код:
CharacterFirstname[playerid][0] = 0; // Empties the string, in case you didn't do it in OnPlayerConnect
strcat(CharacterFirstname[playerid], inputtext, MAX_FIRSTNAME); // Writes inputtext into the array - strcat appends strings, so it must be cleared before (see above)
It must be a multidimensional array, because you don't want to store just one value per player, but a string (array).
Reply
#6

I did that but now i get errors on the following lines:
C:\Users\Abc Winkel\Desktop\New SAMP Project\gamemodes\New.pwn(42197) : error 033: array must be indexed (variable "CharacterFirstname")
C:\Users\Abc Winkel\Desktop\New SAMP Project\gamemodes\New.pwn(42440) : error 035: argument type mismatch (argument 3)
Код:
CharacterFirstname[playerid]=INI_Int(Acc(playerid),"CharacterFirstname"); //line 42197
INI_IntSet(Acc(playerid),"CharacterFirstname",CharacterFirstname[playerid]);//line 42440
Reply
#7

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
I did that but now i get errors on the following lines:
C:\Users\Abc Winkel\Desktop\New SAMP Project\gamemodes\New.pwn(42197) : error 033: array must be indexed (variable "CharacterFirstname")
C:\Users\Abc Winkel\Desktop\New SAMP Project\gamemodes\New.pwn(42440) : error 035: argument type mismatch (argument 3)
Код:
CharacterFirstname[playerid]=INI_Int(Acc(playerid),"CharacterFirstname"); //line 42197
INI_IntSet(Acc(playerid),"CharacterFirstname",CharacterFirstname[playerid]);//line 42440
INI_Int reads a cell value (integer) from an INI file, however a name is not just one integer value, but an array/string.
You must use INI_String and INI_StringSet instead. I never used the ini include so I'm only guessing those are the names.


If they are not working tell me which INI Include you are using and I can tell you the correct way of storing/reading it.
Reply
#8

Quote:
Originally Posted by NaS
Посмотреть сообщение
INI_Int reads a cell value (integer) from an INI file, however a name is not just one integer value, but an array/string.
You must use INI_String and INI_StringSet instead. I never used the ini include so I'm only guessing those are the names.


If they are not working tell me which INI Include you are using and I can tell you the correct way of storing/reading it.
I actually don't know. This are all the includes i use:
#include <a_samp>
#include <fixes>
#include <zcmd>
#include <progress2>
#include <dini>
#include <sscanf2>
#include <streamer>
#include <SpikeStrip>
#include <mSelection>
#include <core>
#include <float>
#include <fly>
#include <evf>
#include <a_actor>
#include "gl_common.inc"

I dont think its dini becuase i use dini for saving other stuff.
Is there a way to save it with dini?

Thank you for your help.
Reply
#9

You must use dini_Set for setting a string, like this:

Код:
dini_Set(Acc(playerid), "CharacterFirstname", CharacterFirstname[playerid]);
and for reading:

Код:
new buffer[DINI_MAX_FIELD_VALUE];
buffer = dini_Get(Acc(playerid), "CharacterFirstname");

// and after that write the buffer to the Array:
CharacterFirstname[playerid][0] = 0;
strcat(CharacterFirstname[playerid], buffer);
I'm not exactly sure about the buffer size. If "DINI_MAX_FIELD_VALUE" doesn't exist, try 128 or 256.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)