PDA

View Full Version : How to get properties to work with include and gamemode?


SkittlesAreFalling
08/12/2013, 07:22 AM
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?

SkittlesAreFalling
09/12/2013, 02:18 PM
Still needing assistance with this subject.

Emmet_
09/12/2013, 11:00 PM
Yeah, the SA-MP wiki has poor documentation on properties.

Here, try this maybe?


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:


stock bernstein(string[])
{
new
hash = -1,
i,
j;
while ((j = string[i++]))
{
hash = hash * 33 + j;
}
return hash;
}

SkittlesAreFalling
10/12/2013, 07:39 PM
Thank you, it works! [+RP]

(With a little but of editing.)