Edit enum with string (+REP)
#8

Quote:
Originally Posted by Sawalha
Посмотреть сообщение
you can't replace a constant enum variable with a randomly created variable,

and this is not the proper way to assign a value to a string variable
firstly, i guess you want to create a string variable in the command, so simply:
pawn Код:
new String[128]; // <- let's assume that the sizeof the string is 128.
secondly, when using string sscanf prefix which is 's', you have to assign the size of it beside it between two brackets, so the sscanf code will be:
pawn Код:
if(sscanf(params,"us[128]i",param[0],String,param[1])) return MSG(playerid,C_RED,"/Set [ID] [Database] [Amount]"); // we added the '[128]' beside the string prefix 's' as you can see, which is the length of 'String' variable.
and then, add to DB's enum the string variable, well, we are not gonna make it's title as same as the string defined in the command which is "String" to avoid warnings, so let's put it as "str", add this to your DB's enum:
pawn Код:
str[128],
and finally, the value assigning, you got a variable for strings in the enum, and you got an independent string variable in your command, we can now assign the value:
pawn Код:
format(DB[params[0]][str], 128, String);
simply, format function is used to assign a string value to a string variable, '=' operator is not the proper way to do it.
- it would be better to create variable for each parameter, i.e, instead of that params[0] and params[1], just add 'id' variable, and a variable for amount, let's call it 'a', and the changes done are:
pawn Код:
new id, a;
if(sscanf(params,"us[128]i",id,String,a)) return MSG(playerid,C_RED,"/Set [ID] [Database] [Amount]");
format(DB[id][str], 128, String);
error 033: array must be indexed (variable "str")


Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
This is happening because you are miss-understanding what enum is, You can think of enum as constant variables that will be replaced by numbers at compile time, so a Money in enum is not a string, but rather a number (for example 6th element in an array), so "Money" as string is not equal to Money of an enum, what you can do is however making a switch
PHP код:
switch(string)
{
case 
"Money":
{
//Set his money bla bla bla
}

C:\Users\мйшп\Desktop\All\GRRP\gamemodes\GlobalDM. pwn(1475) : error 033: array must be indexed (variable "-unknown-")
C:\Users\мйшп\Desktop\All\GRRP\gamemodes\GlobalDM. pwn(1477) : error 001: expected token: "-string end-", but found "-identifier-"
Reply


Messages In This Thread
Edit enum with string (+REP) - by Lirbo - 03.02.2016, 08:47
Re: Edit enum with string (+REP) - by cdoubleoper - 03.02.2016, 09:01
Re: Edit enum with string (+REP) - by Lirbo - 03.02.2016, 09:04
Re: Edit enum with string (+REP) - by cdoubleoper - 03.02.2016, 09:06
Re: Edit enum with string (+REP) - by Lirbo - 03.02.2016, 10:02
Re: Edit enum with string (+REP) - by Sawalha - 03.02.2016, 10:29
Re: Edit enum with string (+REP) - by PrO.GameR - 03.02.2016, 10:38
Re: Edit enum with string (+REP) - by Lirbo - 03.02.2016, 13:47
Re: Edit enum with string (+REP) - by Sawalha - 03.02.2016, 16:17
Re: Edit enum with string (+REP) - by Lirbo - 03.02.2016, 16:51

Forum Jump:


Users browsing this thread: 1 Guest(s)