Weird behaviour of new members to class

Started by karan20000000000, May 31, 2016, 02:51 PM

Previous topic - Next topic

karan20000000000

I added a variable to player's class, joined the server and tried to edit the value of the variable in runtime and it didn't change. It seems as if its behaving like a constant variable.
CPlayer.newmember("ispig",true,null,false);
function onPlayerJoin(player)
{
player.ispig = false;
print(player.ispig); //prints true
}

Any help or theoretical explanations as to why is this happening would be appreciated.
With regards,
KP
------------------------------------------

.

#1
For some reason, instances of CPlayer do not maintain changes on script members after each event. It's the same as getting a new instance each time.

CPlayer.rawnewmember("test", 3, null, false);

function onPlayerRequestSpawn(player)
{
    print(player.test); // 3
    player.test = (player.test + 1);
    print(player.test); // 4
    return 0; // block respawn so we can call it again
}
.

DizzasTeR

I've told you, you can't deal with it, probably the squirrel plugin needs some updates/fixing to get this working, or it may be just screwed up.

Thijn

Or maybe you shouldn't touch classes from the squirrel plugin and make your own instead.

.

Tried it in my plugin just for the lolz and it worked as expected.


Which confirms my suspicion that the official plugin is sending a different CPlayer instance with each triggered event. Maybe it's done by the outdated Sqrat binding utility without even knowing it's supposed to be doing that. Who knows.
.

EK.IceFlake

Quote from: . on May 31, 2016, 05:13 PMWhich confirms my suspicion that the official plugin is sending a different CPlayer instance with each triggered event. Maybe it's done by the outdated Sqrat binding utility without even knowing it's supposed to be doing that. Who knows.
Which can be further proved by either
print("Instance: " + player);
which will return a new address every time, or:
local plr = FindPlayer(player.ID);
print("Matches: " + (player == plr ? "Yes" : "No"));
which will return No every time.

.

Quote from: ext-d.CrystalBlue on May 31, 2016, 06:29 PMWhich can be further proved by either
print("Instance: " + player);
which will return a new address every time...

It implements the _tostring metamethod so you get the player name instead of an address.
.

karan20000000000

Quote from: Thijn on May 31, 2016, 04:43 PMOr maybe you shouldn't touch classes from the squirrel plugin and make your own instead.
Why not do that when the functionality is available and all we need to do is (hopefully) couple of fixes in the squirrel plugin before being able to do this?
With regards,
KP
------------------------------------------