Hi everybody!
I have a Module called FireFly with this simple header:
struct FireFly {
import function CreateFlies();
//in repeatedly execute
import function UpdateFlies();
};
So, this is part my RoomScript:
//Create instance of FireFly-Struct
FireFly thisroom;
#sectionstart room_b // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
// script for Room: Player enters room (before fadein)
thisroom.CreateFlies(); //<===== !!!!! THIS LINE CAUSES THE ERROR !!!!!
}
#sectionend room_b // DO NOT EDIT OR REMOVE THIS LINE
It refers to this section of my FireFly-Module:
function FireFly::CreateFlies() {
Mouse.Visible = false;
int i;
while(i < 3) {
//DoStuff
}
}
AGS compiles fine. However, just when the room is about to load I get an error saying:
"Null pointer referenced" in the line I indicated.
Is that enough information for you to have any ideas what I did wrong?
Many thanks in advance,
Stefan
Try "mouse.Visible=false;".
Actually I'd tried both, seems that they both worked (the mouse. variables were left because of compatibility with old versions, if you read the manual for these entries you'll see they're referred inconsistently as both Mouse.Visible and mouse.Visible).
In your header:
struct FireFly {
import static function CreateFlies();
//in repeatedly execute
import static function UpdateFlies();
};
And in your script file
static function FireFly::CreateFlies() {
Otherwise you need to export the struct in the module header, and import it in your global script... Either works, but it's just generally easier to make them static.
Well thanks everybody. I followed your advices but they didn't solve the problem.
However, I just found out what caused the error:
static function FireFly::CreateFlies() {
Mouse.Visible = false;
int i; <=== !!!!! CHANGE THIS VARIABLE NAME TO 'y' !!!!!
while(i < 3) {
//DoStuff
}
}
If I changed the variable name from 'i' to 'y' everything worked perfect.
I don't really get why this happened:
I declared variables with the same name 'i' in other functions of my module as well, but I always thought that you can have the same variable names across several functions as long as you create the variable within a function.
So in my opinion the following should be possible:
function Test_One() {
int i;
//DoStuff
}
function Test_Two() {
int i;
//DoMoreStuff
}
Isn't that allowed?
That should be okay, are you sure that i wasn't also declared outside of the functions?
Well, very very strange .... I just changed the name of the variable back to 'i' and it works like a charm now. I didn't change the script in any other way...
Anyway, thank you very much for your input!
See you next time :-)
Stefan
Hum...
Shouldn't you be initializing 'i'?
int i = 0;
while (i < 3) {
// Do stuff
}
Local variables are initialized to 0 by default (http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=271) as of AGS v2.70.