How to get properties to work with include and gamemode?
#1

These are examples of what I'm trying to do.

Include:
Код:
#define SAF: SAF_

#define MaxString (1028)

#define SetString(%0,%1) setproperty(.value = (getproperty(.name =%0) + MaxString), .string =%1)
#define GetString(%0) (getproperty(.value = (getproperty(.name =%0) + MaxString), .string = SAF:String), strunpack(SAF:String, SAF:String, MaxString), SAF:String)

new SAF:String[MaxString];

stock SetVariables() {
	SetString("Test", "This is a test.");
	SetString("Test2", "This is a second test.");
	
	new String[100] = "This is a third test.";
	
	SetString("Test3", String);
	return true;
}
Gamemode:
Код:
public OnGameModeInit() {
	SetVariables();

	print(GetString("Test"));
	print(GetString("Test2"));
	print(GetString("Test3"));
	return true;
}
This example won't work.

Include:
Код:
#define SAF: SAF_

#define MaxString (1028)

#define SetString(%0,%1) setproperty(.value = (getproperty(.name =%0) + MaxString), .string =%1)
#define GetString(%0) (getproperty(.value = (getproperty(.name =%0) + MaxString), .string = SAF:String), strunpack(SAF:String, SAF:String, MaxString), SAF:String)

new SAF:String[MaxString];
Gamemode:
Код:
public OnGameModeInit() {
	SetString("Test", "This is a test.");
	SetString("Test2", "This is a second test.");
	
	new String[100] = "This is a third test.";
	
	SetString("Test3", String);

	print(GetString("Test"));
	print(GetString("Test2"));
	print(GetString("Test3"));
	return true;
}
This example will work.

How do I get properties to work with include and gamemode as one?
Reply
#2

Still needing assistance with this subject.
Reply
#3

Yeah, the SA-MP wiki has poor documentation on properties.

Here, try this maybe?

pawn Код:
static
    g_Str[128];

#define SetString(%0,%1) \
    (setproperty(0, "", bernstein(%0), %1))

#define GetString(%0) \
    (getproperty(0, "", bernstein(%0), g_Str))
You also need "bernstein" from y_utils - here's a direct copy of the function:

pawn Код:
stock bernstein(string[])
{
    new
        hash = -1,
        i,
        j;
    while ((j = string[i++]))
    {
        hash = hash * 33 + j;
    }
    return hash;
}
Reply
#4

Thank you, it works! [+RP]

(With a little but of editing.)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)