Gamemode creation problem

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
mewin
Posts: 24
Joined: 15 Aug 2012, 14:45
Contact:

Gamemode creation problem

Post by mewin »

I have a problem creating a new gamemode. For some reason a variable containing a Event contains a Player in the next line.

Code:

Code: Select all

...
log(Event);
if (Event.Type == CSmModeEvent::EType::OnArmorEmpty) {
  log(Event);
  if (Event.Shooter == Event.Victim || Event.Shooter == Null) {
    Score::RemovePoints(Event.Victim, 1);
  }
  PassOn(Event);
} else if (Event.Type == CSmModeEvent::EType::OnHit) {
...
Console output:

Code: Select all

(CSmArenaRulesEvent*)
[295, 21] Invalid access to parameter (Null object or elem not found in array) : Players[0]>.Type
I just copied the source of Melee and changed something, now I get this error and don't get the problem.

Full source
User avatar
Awpteamoose
Posts: 76
Joined: 12 Jul 2012, 20:27

Re: Gamemode creation problem

Post by Awpteamoose »

CSmModeEvent::EType::OnArmorEmpty doesn't always have Event.Shooter, you're trying to access an illegal variable in some cases.
You should do something like:

Code: Select all

if (Event.Type == CSmModeEvent::EType::OnArmorEmpty) {
    if ( Event.Shooter == Null || Event.Victim == Null || Event.Shooter == Event.Victim ) {
        Discard(Event);
    } else ...
mewin
Posts: 24
Joined: 15 Aug 2012, 14:45
Contact:

Re: Gamemode creation problem

Post by mewin »

That is not the problem.

1. I copied this from the Melee script, it should be correct. (Event.Shooter could be Null, but this doesnt change anything)

2. I got the problem that Event somehow does not contain the event anymore.

Anyway thank you for your help ^^

Edit: I found out how to fix it, but still don't get why that happened. If someone has the same problem: I could fix it by removing a switch-case and replacing it with multiple if's.
User avatar
Awpteamoose
Posts: 76
Joined: 12 Jul 2012, 20:27

Re: Gamemode creation problem

Post by Awpteamoose »

mewin wrote:1. I copied this from the Melee script, it should be correct. (Event.Shooter could be Null, but this doesnt change anything)
My bad, I'm blind.
mewin wrote:2. I got the problem that Event somehow does not contain the event anymore.

Anyway thank you for your help ^^

Edit: I found out how to fix it, but still don't get why that happened. If someone has the same problem: I could fix it by removing a switch-case and replacing it with multiple if's.
Not sure what the code was, but maybe you didn't PassOn the event and it dismissed it and gave you Null when the event queue was empty.
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: Gamemode creation problem

Post by Eole »

I checked the script, the problem was indeed in the Switch structure of the SetRoll function. In ManiaScript you mustn't use the break instruction at the end of a case. That was producing some strange cascading loop breaking. ^^'
The compiler will be updated to throw an error on such case at compilation time to avoid confusion in the future.
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest