SA-MP Forums Archive
How to get properties to work with include and gamemode? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to get properties to work with include and gamemode? (/showthread.php?tid=479958)



How to get properties to work with include and gamemode? - SkittlesAreFalling - 08.12.2013

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?


Re: How to get properties to work with include and gamemode? - SkittlesAreFalling - 09.12.2013

Still needing assistance with this subject.


Re: How to get properties to work with include and gamemode? - Emmet_ - 09.12.2013

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;
}



Re: How to get properties to work with include and gamemode? - SkittlesAreFalling - 10.12.2013

Thank you, it works! [+RP]

(With a little but of editing.)