Array combined with virtual world isn't giving me the correct index.
#1

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(playerid2203.8129,-50.1708,1001.8047)) {
                                
SetTimerEx("UnfreezePlayer"3000false"i"playerid);
                                
TogglePlayerControllable(playeridfalse);
                                
SetPlayerPos(playeridClothes[2000-GetPlayerVirtualWorld(playerid)][scOutX], Clothes[2000-GetPlayerVirtualWorld(playerid)][scOutY], Clothes[2000-GetPlayerVirtualWorld(playerid)][scOutZ]); //assuming this is the faulty line
                                
SetPlayerInterior(playerid0);
                                
SetPlayerVirtualWorld(playerid0);
                                
cmd_me(playerid"exits the building.");
                            } 
This was how I set the world:
PHP код:
SetPlayerVirtualWorld(playeridi+2000); 
Reply
#2

2000-GetPlayerVirtualWorld(playerid) -> GetPlayerVirtualWorld(playerid)-2000
Reply
#3

Quote:
Originally Posted by Spmn
Посмотреть сообщение
2000-GetPlayerVirtualWorld(playerid) -> GetPlayerVirtualWorld(playerid)-2000
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
Reply
#4

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?
Reply
#5

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
Reply
#6

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
Reply
#7

What's max size of clothes enum
Reply
#8

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 :((
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)