Page 1 of 1

Gamemode creation problem

Posted: 23 Sep 2012, 15:49
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

Re: Gamemode creation problem

Posted: 23 Sep 2012, 18:20
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 ...

Re: Gamemode creation problem

Posted: 23 Sep 2012, 18:36
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.

Re: Gamemode creation problem

Posted: 24 Sep 2012, 00:11
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.

Re: Gamemode creation problem

Posted: 24 Sep 2012, 18:56
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.