SphereCommunity
Calling functions - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: Calling functions (/Thread-Calling-functions)



Calling functions - hctez - 08-20-2015 11:17 AM

Hello, i was wondering what is the difference between calling a function from an item, a player or using serv?
If i have a function that doesn't interact with a player or an item, for example a function that adds stuff to a list:

[function test]
list.test.add something
....
...

Is there a difference?


RE: Calling functions - darksun84 - 08-20-2015 08:38 PM

What actually changes is the type of the SRC object and default object (I).
So if you call a function from an item, the SRC object and the default object (I) references an item type, if you call from a character the SRC and default references to a character type .

The type means what default proprerties/function (like STR for a character) can be accessed from both SRC and the default object (I).
In your case the LIST command is a "global" command and can be used in a function that is called by items,characters and server object.

I am also sure that when calling a function from the server object, both SRC and default object are set to the server object only when the function is launched from the console.

Example:
[FUNCTION test]
log <name> <src.name>
serv.log <name> <src.name>

If this function is launched from the console the results will be:
1st line) Myshardname Myshardname
2nd line) Myshardname Myshardname

If this function is launched in game by typing .test the results will be:
1st line) An error, because log isn't accessible by a character type
2nd line) Myshardname, Charactername

If this function is launched in game by typing .serv.test the results will be:
1st line) Myshardname, CharacterName
2nd line) Myshardname, CharacterName

Even if you typed .serv.test the source object that called the function is still a character.


RE: Calling functions - hctez - 08-21-2015 05:02 AM

Thanks for answering, i already knew that, my question is when i have a function where i don't need to use any of those properties, is there a difference? Like the example function i use in my post. I can call that function from a player, item or using serv, and the result will be the same (add items to a list) but maybe is better to call it from serv instead of a random item for some reason, that was my question.
I talking maybe from a design or performance point of view

Thanks


RE: Calling functions - darksun84 - 08-21-2015 05:10 AM

In a script, even if the function doesn't interact with a character or an item, most of time the one that call the function is an item or an character. As I wrote, the only way to set the SRC as the server object is to call the function from the server's console or use TRYSRV.

So at the end it doesn't matter Tongue

So i can understand better, when this function will be called ?