PDA

View Full Version : core.inc properties


Amit_B
04/07/2012, 06:57 AM
Lately I had an interesting conversation at SA-MP mIRC. We've talked about the four old functions that defined in PAWN as default in core.inc; the property() functions (getproperty, setproperty, existproperty, deleteproperty).

I'm opening this thread so we can all share information about these functions because currently they're unknown to most of scripters in SA-MP but looks like they can be really useful just as most of the rest of functions in core.inc. Not a lot is known about these functions.

Anyway, I know that these functions used to create server-side variables that saved in the entire server. By using these functions instead of normal variables we can define a formatted variable name. It means we can decide the name of a variable just by a string. Also, by SA-MP wiki there are new documention added to these functions and from them it looks like there are two ways to create such a variable. The first is to define integer property and the other is to define a string, and both uses different codes in the setproperty() (http://wiki.sa-mp.com/wiki/Setproperty) parameters. I've also found that when loading or unloading a filterscript, or changing gamemode, all of the defined variables gets reseted.

I've found a lot of uses for these functions. For example, I got a dynamic logs (server history) system, which is controlled by a function that requires the name of the log (Connections, Stats, Commands, etc). I wanted to write to the log file a message when the log first edited (so in case of server crashing, the message will seperate the log file from the text before the crash and the text after the crash). To do that, i've used properties to set a property that his name is the name of the log and the value is doesn't matter here. When writing to log I just check if the property exist, if so i'll write to the log, if not i'll add the line i've mentioned before and then the text to write.

There are a lot of other ways to use these functions, and after so much time that passed from creating SA-MP, I think it's time that people will know this option.

Chaprnks
04/07/2012, 07:27 AM
I was very interested in these functions as-well. I have a pretty large gamemode to modify so if I'd go through all that work I would prefer PVar (& GVar when necessary). Do you know if the property functions have any speed differences between PVar & normal variables? Thanks for the information though, I'm glad to see there's still some curious minded people like me, on this forum:)

Vince
04/07/2012, 10:35 AM
I, in fact, edited that article with the example of saving integers using the information provided on page 130 of the manual. These functions basically serve the same purpose as the GVar plugin in that they can be shared throughout all scripts. Float values cannot be saved, though (I think).

Amit_B
04/07/2012, 10:46 AM
I, in fact, edited that article with the example of saving integers using the information provided on page 130 of the manual. These functions basically serve the same purpose as the GVar plugin in that they can be shared throughout all scripts. Float values cannot be saved, though (I think).
Sure they can, just by saving a string and using floatstr().

steki.
04/07/2012, 11:10 AM
Sure they can, just by saving a string and using floatstr().

Or saved as int and Float: them.

---

Well, properties are a pretty old group of functions and I believe GVars were created to replace those functions because of the speed.

Vince
04/07/2012, 11:13 AM
Someone should actually test the speed of both. I think Pawn natives are still faster than plugin natives.

Amit_B
04/07/2012, 12:06 PM
I guess that the creators of GVar (both plugin and include) just didn't knew these functions...

Y_Less
04/07/2012, 01:06 PM
We're (http://forum.sa-mp.com/showthread.php?p=1417957&highlight=properties#post1417957) Advocating (http://forum.sa-mp.com/showthread.php?p=1384086&highlight=properties#post1384086) The (http://forum.sa-mp.com/showthread.php?p=1289094&highlight=properties#post1289094) Use (http://forum.sa-mp.com/showthread.php?p=1277071&highlight=properties#post1277071) Of (http://forum.sa-mp.com/showthread.php?p=1231421&highlight=properties#post1231421) Properties (http://forum.sa-mp.com/showthread.php?p=1104728&highlight=properties#post1104728) Now? (http://forum.sa-mp.com/showthread.php?p=1098272&highlight=properties#post1098272) What (http://forum.sa-mp.com/showthread.php?p=426060&highlight=properties#post426060) A (http://forum.sa-mp.com/showthread.php?p=432243&highlight=properties#post432243) Novel (http://forum.sa-mp.com/showthread.php?p=426757&highlight=properties#post426757) Idea! (http://forum.sa-mp.com/showthread.php?p=112371&highlight=properties#post112371) I've (http://forum.sa-mp.com/showthread.php?p=1098230&highlight=properties#post1098230) Not (http://forum.sa-mp.com/showthread.php?p=1048967&highlight=properties#post1048967) Seen (http://forum.sa-mp.com/showthread.php?p=956458&highlight=properties#post956458) That (http://forum.sa-mp.com/showthread.php?p=871861&highlight=properties#post871861) Before... (http://forum.sa-mp.com/showthread.php?p=827598&highlight=properties#post827598)

Amit_B
04/07/2012, 02:21 PM
Where (http://forum.sa-mp.com/member.php?u=29176) have (http://forum.sa-mp.com/member.php?u=29176) you (http://forum.sa-mp.com/member.php?u=29176) find (http://forum.sa-mp.com/member.php?u=29176) all (http://forum.sa-mp.com/member.php?u=29176) of (http://forum.sa-mp.com/member.php?u=29176) these (http://forum.sa-mp.com/member.php?u=29176) replies? (http://forum.sa-mp.com/member.php?u=29176)
It's (http://forum.sa-mp.com/member.php?u=29176) so (http://forum.sa-mp.com/member.php?u=29176) good (http://forum.sa-mp.com/member.php?u=29176) to (http://forum.sa-mp.com/member.php?u=29176) know (http://forum.sa-mp.com/member.php?u=29176) that (http://forum.sa-mp.com/member.php?u=29176) there (http://forum.sa-mp.com/member.php?u=29176) are (http://forum.sa-mp.com/member.php?u=29176) more (http://forum.sa-mp.com/member.php?u=29176) scripters (http://forum.sa-mp.com/member.php?u=29176) using (http://forum.sa-mp.com/member.php?u=29176) it. (http://forum.sa-mp.com/member.php?u=29176)

It will not be that bad if you'll try a little to understand people and be more nice to them. :)

Y_Less
04/07/2012, 02:32 PM
Yes I know where I found them, my point was I've been telling people about this for at least three years - I do sometimes think I'm talking to myself!

Basssiiie
04/07/2012, 02:58 PM
I don't use properties very often, but I do use them sometimes. So I guess Y_less isn't the only one who uses them. ;)

Amit_B
04/07/2012, 03:08 PM
Yes I know where I found them, my point was I've been telling people about this for at least three years - I do sometimes think I'm talking to myself!
ah, sorry, I was getting you wrong. looks like we're in the same opinion.

AndreT
07/07/2012, 07:01 AM
Someone should actually test the speed of both. I think Pawn natives are still faster than plugin natives.
The GVar plugin thread (http://forum.sa-mp.com/showthread.php?t=151076&page=4) has plenty of test results posted, along with one comparing properties to GVars (http://forum.sa-mp.com/showpost.php?p=703181&postcount=33) by Incognito. This should say enough.

Finn
07/07/2012, 01:05 PM
Like AndreT already mentioned: just use GVars instead. Easier to use + faster, so why not.

Bharel
27/08/2013, 09:31 AM
We're (http://forum.sa-mp.com/showthread.php?p=1417957&highlight=properties#post1417957) Advocating (http://forum.sa-mp.com/showthread.php?p=1384086&highlight=properties#post1384086) The (http://forum.sa-mp.com/showthread.php?p=1289094&highlight=properties#post1289094) Use (http://forum.sa-mp.com/showthread.php?p=1277071&highlight=properties#post1277071) Of (http://forum.sa-mp.com/showthread.php?p=1231421&highlight=properties#post1231421) Properties (http://forum.sa-mp.com/showthread.php?p=1104728&highlight=properties#post1104728) Now? (http://forum.sa-mp.com/showthread.php?p=1098272&highlight=properties#post1098272) What (http://forum.sa-mp.com/showthread.php?p=426060&highlight=properties#post426060) A (http://forum.sa-mp.com/showthread.php?p=432243&highlight=properties#post432243) Novel (http://forum.sa-mp.com/showthread.php?p=426757&highlight=properties#post426757) Idea! (http://forum.sa-mp.com/showthread.php?p=112371&highlight=properties#post112371) I've (http://forum.sa-mp.com/showthread.php?p=1098230&highlight=properties#post1098230) Not (http://forum.sa-mp.com/showthread.php?p=1048967&highlight=properties#post1048967) Seen (http://forum.sa-mp.com/showthread.php?p=956458&highlight=properties#post956458) That (http://forum.sa-mp.com/showthread.php?p=871861&highlight=properties#post871861) Before... (http://forum.sa-mp.com/showthread.php?p=827598&highlight=properties#post827598)

Genius I tell you. +1

JoBullet
27/08/2013, 07:10 PM
The "properties" are implemented by means of singly linked list (ref:https://code.google.com/p/pawnscript/source/browse/trunk/amx/amxcore.c), while GVar plugin is implemented by means of hash table (I assume standard implementation).
The Wikipedia has the info about Big-Oh of both implementations so you can compare their time complexities.
Big-Oh of singly linked list: http://en.wikipedia.org/wiki/Linked_list#Linked_lists_vs._dynamic_arrays
Big-Oh of hash tables: http://en.wikipedia.org/wiki/Hash_table