Array combined with virtual world isn't giving me the correct index. -
Meller - 05.09.2017
Basically what the title says, this code simply returns
Код:
[debug] Run time error 4: "Array index out of bounds"
[debug] Attempted to read/write array element at negative index -1
[debug] AMX backtrace:
[debug] #0 00040bd8 in public OnPlayerKeyStateChange (0, 16, 0) from rp.amx
PHP код:
if(IsPlayerInRangeOfPoint(playerid, 2, 203.8129,-50.1708,1001.8047)) {
SetTimerEx("UnfreezePlayer", 3000, false, "i", playerid);
TogglePlayerControllable(playerid, false);
SetPlayerPos(playerid, Clothes[2000-GetPlayerVirtualWorld(playerid)][scOutX], Clothes[2000-GetPlayerVirtualWorld(playerid)][scOutY], Clothes[2000-GetPlayerVirtualWorld(playerid)][scOutZ]); //assuming this is the faulty line
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
cmd_me(playerid, "exits the building.");
}
This was how I set the world:
PHP код:
SetPlayerVirtualWorld(playerid, i+2000);
Re: Array combined with virtual world isn't giving me the correct index. -
Spmn - 05.09.2017
2000-GetPlayerVirtualWorld(playerid) -> GetPlayerVirtualWorld(playerid)-2000
Re: Array combined with virtual world isn't giving me the correct index. -
Meller - 05.09.2017
Quote:
Originally Posted by Spmn
2000-GetPlayerVirtualWorld(playerid) -> GetPlayerVirtualWorld(playerid)-2000 ![Huh?](images/smilies/confused.gif)
|
That would fuck my code up more, didn't you pay attention to 3rd grade math in primary school?
0-2000 = -2000
1-2000 = -1999
https://www.youtube.com/watch?v=hJWMLdDBHqw
Re: Array combined with virtual world isn't giving me the correct index. -
Spmn - 05.09.2017
Quote:
Originally Posted by Meller
That would fuck my code up more, didn't you pay attention to 3rd grade math in primary school?
|
Me or you?
Код:
SetPlayerVirtualWorld(playerid, i+2000);
Let's say i = 1
i+2000 = 2001
GetPlayerVirtualWorld = 2001
2001 - 2000 = 1
i = 1
hard?
Re: Array combined with virtual world isn't giving me the correct index. -
Meller - 05.09.2017
Quote:
Originally Posted by Spmn
Me or you?
Код:
SetPlayerVirtualWorld(playerid, i+2000);
Let's say i = 1
i+2000 = 2001
GetPlayerVirtualWorld = 2001
2001 - 2000 = 1
i = 1
|
You told me to subtract 2000 from 2001, read what you told me to do; change 2001-2000 to 2000-2001.
i = 1
world = i+2000 = 2001
later:
i = 1
world = 2001
-world|||||||||||||||||||||||||||||||||||||||||||||
i just realized that i was doing it wrong, lmfao
my bad pal
Re: Array combined with virtual world isn't giving me the correct index. -
Paulice - 06.09.2017
You got
roasted, buddy!
-----
O.T. When issues like this arise, debug values! It's easy to spot where the issues are doing so.
e.g. printf("%i", 2000-GetPlayerVirtualWorld(playerid)); - as this originates the array index out of bounds run time error
Re: Array combined with virtual world isn't giving me the correct index. -
iLearner - 06.09.2017
What's max size of clothes enum
Re: Array combined with virtual world isn't giving me the correct index. -
Meller - 06.09.2017
Quote:
Originally Posted by Paulice
You got roasted, buddy!
-----
O.T. When issues like this arise, debug values! It's easy to spot where the issues are doing so.
e.g. printf("%i", 2000-GetPlayerVirtualWorld(playerid)); - as this originates the array index out of bounds run time error
|
I'm full of the burn smell :((