Raised This Month: $51 Target: $400
 12% 

Solved out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 04-19-2020 , 18:50   out of bounds
Reply With Quote #1

L 04/19/2020 - 14:46:56: [AMXX] Displaying debug trace (plugin "survminigun.amxx")
L 04/19/2020 - 14:46:56: [AMXX] Run time error 4: index out of bounds
L 04/19/2020 - 14:46:56: [AMXX] [0] cominigun.sma::event_start (line 234)

PHP Code:
public event_start(){
    static 
iPlayers[32], iPlayersNum
    get_players
(iPlayersiPlayersNum"a")
    for (
0<= iPlayersNum; ++i)
        
canfire[iPlayers[i]] = true

__________________
a simple act of caring creates an endless ripple.

Last edited by Bugsy; 04-21-2020 at 21:30.
Nutu_ is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-19-2020 , 19:05   Re: out of bounds
Reply With Quote #2

iPlayersNum is the number of players, not the largest index of the array because arrays are zero-indexed. So, the last index that you use will be iPlayersNum - 1 so in your for loop, you use:

Code:
i < iPlayersNum
__________________

Last edited by fysiks; 04-19-2020 at 19:07.
fysiks is offline
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 04-19-2020 , 19:11   Re: out of bounds
Reply With Quote #3

like
PHP Code:
for (0iPlayersNum; ++i
or just
PHP Code:
iPlayersNum 
__________________
a simple act of caring creates an endless ripple.
Nutu_ is offline
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 04-20-2020 , 08:56   Re: out of bounds
Reply With Quote #4

Quote:
Originally Posted by Nutu_ View Post
like
PHP Code:
for (0iPlayersNum; ++i

Last edited by Fuck For Fun; 04-20-2020 at 08:56.
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-20-2020 , 09:01   Re: out of bounds
Reply With Quote #5

Code:
public event_start(){     arrayset(canfire, false, sizeof(canfire)) }
__________________

Last edited by OciXCrom; 04-20-2020 at 09:01.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 04-21-2020 , 14:29   Re: out of bounds
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
Code:
public event_start(){     arrayset(canfire, false, sizeof(canfire)) }
seems to work, thank you!
__________________
a simple act of caring creates an endless ripple.
Nutu_ is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-22-2020 , 06:32   Re: out of bounds
Reply With Quote #7

Quote:
Originally Posted by Nutu_ View Post
seems to work, thank you!
Basicly, it's the same thing, just less typing.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-22-2020 , 21:22   Re: out of bounds
Reply With Quote #8

Quote:
Originally Posted by Napoleon_be View Post
Basicly, it's the same thing, just less typing.
Actually, it's not the same. It likely depends on how the array is being used but using arrayset() is most likely to be the correct solution.
__________________

Last edited by fysiks; 04-22-2020 at 21:23.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-22-2020 , 22:50   Re: out of bounds
Reply With Quote #9

I think what he was getting at is you end up with the same result, which is true...and it is less typing/code.

Not only is it less code, but arrayset() is avoiding the need to call get_players() and then a subsequent for-loop. arrayset() cannot be used for all situations, which is what fysiks was getting at, but in this case it can be used.
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-22-2020 , 23:17   Re: out of bounds
Reply With Quote #10

If it's a situation where canfire is being used as a "once per event" flag, it's possible that someone joins after the "event" occurs and uses a slot that wasn't properly reset with the get_players() method. Then, the new player could be deprived of their one use of that function. In this specific scenario, arrayset() is the only correct solution (between the two options listed here).
__________________

Last edited by fysiks; 04-22-2020 at 23:18.
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode