Whenever I try to run this script from repeatedly_execute, I get an error ("null pointer referenced"):
char prevAt = -1;
function dlgHighlight() {
/* highlight the (complete) dialog option under the cursor */
GUIControl* controlAt = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (controlAt != null) {
char objAt = 0;
while ((objAt < 7) && (controlAt.ID != objAt)) { objAt++; }
if (prevAt != -1) {
if (objAt != prevAt) {
gDialog.Controls[prevAt].AsLabel.TextColor = 31055; /* release previous item */
gDialog.Controls[objAt].AsLabel.TextColor = 13; /* highlight current */
prevAt = objAt; /* store item */
}
else {} /* still over previous item */
}
else { /* runs only once */
gDialog.Controls[objAt].AsLabel.TextColor = 13; /* highlight current item */
prevAt = objAt;
}
}
else { /* null control - release all items*/
char buf = 0;
while (buf < 7) {
gDialog.Controls[buf].AsLabel.TextColor = 31055;
buf++;
}
}
}
The problem is that
if (controlAt != null) {
char objAt = 0;
while ((objAt < 7) && (controlAt.ID != objAt)) { objAt++; }
the "if (controlAt != null) {" line doesn't appear to be catching whether the pointer is actually null as the null pointer reference is a limit for the while loop. Either that or somehow the only line in-between the two "char objAt = 0;" is causing the pointer to become null. What is going on here?
The problem is on the line:
Edit: The problem has moved from line 346 to line 349. I made no changes since last night.
gDialog.Controls[prevAt].AsLabel.TextColor = 31055; /* release previous item */
And the line that called it (374) (in repeatedly_execute()):
dlgHighlight(); /* highlight dialog */
Quote from: Error Message---------------------------
Adventure Game Studio
---------------------------
An internal error has occured. Please note down the following information.
If the problem persists, contact Chris Jones.
(ACI version 2.70.856)
Error: run_text_script1: error -6 running function 'repeatedly_execute':
Error: Null pointer referenced
in Global script (line 349)
from Global script (line 374)
---------------------------
OK
---------------------------
Last night the error was on line 346. At least I thought it was...Perhaps I was just mistaken because I was tired. I don't know. I've edited the code...I don't know why I didn't just set objAt to the control ID in the first place, but this code makes more sense (doesn't solve the problem, just makes more sense):
char prevAt = -1;
function dlgHighlight() {
/* highlight the (complete) dialog option under the cursor */
GUIControl* controlAt = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (controlAt != null) {
char objAt = 0;
objAt = controlAt.ID;
if (prevAt != -1) {
if (objAt != prevAt) {
gDialog.Controls[prevAt].AsLabel.TextColor = 31055; /* release previous item */
gDialog.Controls[objAt].AsLabel.TextColor = 13; /* highlight current */
prevAt = objAt; /* store item */
}
else {} /* still over previous item */
}
else { /* runs only once per game -- initializes prevAt */
gDialog.Controls[objAt].AsLabel.TextColor = 13; /* highlight current item */
prevAt = objAt;
}
}
else { /* null control -- release all items*/
char buf = 0;
while (buf < 7) {
gDialog.Controls[buf].AsLabel.TextColor = 31055;
buf++;
}
}
}
There was no change in the line numbers, and I got the same error message. I'll try commenting the line, but I don't know if it will help.
Edit: Commenting the problem line prevented the error, but now the labels are not returned to their normal color (31055) until the controlAt parameter is null...
Edit: Solved.
if (objAt != prevAt) {
if (gDialog.Controls[prevAt] != null)
gDialog.Controls[prevAt].AsLabel.TextColor = 31055; /* release previous item */