Page 1 of 1

Invalid access to parameter

Posted: 28 Jul 2014, 20:01
by Mariomarco
Hey Community,
I have the following code with this error Message:
Maniaplanet wrote:Invalid access to parameter (Null object or elem not found in array) : PendingEvents[0]>.Shooter
I know that I need to check weather _Player is Null, so I did:

Code: Select all

if(_Player == Null) return;
after checking I run this code:

Code: Select all

if(!ScoreList.existskey(_Player)) ScoreList[_Player] = 0;
Help would be greatly appreciated.

Marco

PS:
If you didn't notice the function gets called from PendingEvents

Re: Invalid access to parameter

Posted: 28 Jul 2014, 22:09
by steeffeen
Mariomarco wrote:
Invalid access to parameter (Null object or elem not found in array) : PendingEvents[0]>.Shooter
this message doesn't belong to the shown code
it's saying "PendingEvents[0]>.Shooter", which means that PendingEvents[0] doesn't exist
how are you accessing the events?

Re: Invalid access to parameter

Posted: 29 Jul 2014, 13:38
by Eole
One possibility could be that you have a yield/sleep/wait between the call to the function with this player in the parameters and the time when you use the player in the function. Any instruction that would end the current script frame will also flush the event array, so the shooter you're trying to access doesn't exist anymore.

Another advice is to avoid to save a CSmPlayer into a variable (or in your case as an array key) if you need to access it later after a yield. It's safer to save the player Id and retrieve it from the Players array when you need it.

Re: Invalid access to parameter

Posted: 29 Jul 2014, 19:23
by Mariomarco
@steeffeen:
I access it via:

Code: Select all

foreach (Event, PendingEvents) {
	if (Event.Type == CSmModeEvent::EType::OnHit) {
		if (Event.Victim ==Null || Event.Shooter == Event.Victim || Event.Shooter ==  Null) {

			Discard(Event);
		}else{
			givePoints(Event.Shooter, ...);
		}
	}else {
		PassOn(Event);
	}
}
@Eole:
Ok, I'll check.

Re: Invalid access to parameter

Posted: 03 Aug 2014, 08:27
by alividerci
Event.Shooter == Null
How is it? Bot?

Re: Invalid access to parameter

Posted: 04 Aug 2014, 11:41
by Mariomarco
alividerci wrote:
Event.Shooter == Null
How is it? Bot?
No, bots could also be Shooters.
You should just check if everything is like it's supposed to be.

Btw. My error was to discard the event after I used it and not to pass it on.

Re: Invalid access to parameter

Posted: 04 Aug 2014, 22:18
by alividerci
Mariomarco wrote:
alividerci wrote:
Event.Shooter == Null
How is it? Bot?
No, bots could also be Shooters.
You should just check if everything is like it's supposed to be.

Btw. My error was to discard the event after I used it and not to pass it on.
Which diffrent between passon and discard. And for what use?