Invalid access to parameter

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
Mariomarco
Posts: 52
Joined: 23 Jul 2012, 16:02

Invalid access to parameter

Post 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
Image
User avatar
steeffeen
Translator
Translator
Posts: 2463
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: Invalid access to parameter

Post 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?
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks
    User avatar
    Eole
    Nadeo
    Nadeo
    Posts: 1265
    Joined: 26 Apr 2011, 21:08

    Re: Invalid access to parameter

    Post 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.
    Contribute to the ManiaPlanet documentation on GitHub
    A question about ManiaScript? Ask it here!
    Mariomarco
    Posts: 52
    Joined: 23 Jul 2012, 16:02

    Re: Invalid access to parameter

    Post 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.
    Image
    User avatar
    alividerci
    Posts: 363
    Joined: 11 Feb 2012, 07:03

    Re: Invalid access to parameter

    Post by alividerci »

    Event.Shooter == Null
    How is it? Bot?
    Mariomarco
    Posts: 52
    Joined: 23 Jul 2012, 16:02

    Re: Invalid access to parameter

    Post 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.
    Image
    User avatar
    alividerci
    Posts: 363
    Joined: 11 Feb 2012, 07:03

    Re: Invalid access to parameter

    Post 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?
    Post Reply

    Return to “ManiaScript”

    Who is online

    Users browsing this forum: No registered users and 1 guest