what does this error message mean? (SOLVED)

Started by EnterTheStory (aka tolworthy), Mon 10/12/2007 08:21:37

Previous topic - Next topic

EnterTheStory (aka tolworthy)

It's six years since I last did any real programming, so my apologies if this is something obvious. Here's my original code:

int typeUnderMouse;   
function repeatedlyCheckStatus()
{   typeUnderMouse =0;   
   if (GetLocationType(mouse.x,mouse.y) == eLocationHotspot) typeUnderMouse =1;
   if (GetLocationType(mouse.x,mouse.y) == eLocationCharacter) typeUnderMouse =2;
   if (GetLocationType(mouse.x,mouse.y) == eLocationObject) typeUnderMouse =3;
   SetGlobalInt(1,typeUnderMouse);
   if(typeUnderMouse ==1)      // line 24
   { // do stuff
   }

And here's the error message:

"There was an error compiling your script. The problem was: In: 'repeatedExecute' Error (line 24): must have an instance of the struct to access a non-static member"

Can someone remind me what "an instance of the struct to access a non-static member" actually means?

Also, is there any way to save a game before the compile bugs are fixed? When I try to save I get the "you have an error, your game was not saved" message. It was late at night so I had to just leave the computer on and hope nothing happens to lose the day's work (e.g. crazy pets / environmentally conscious "turn everything off" grandparents / normal winter power cuts in my village / etc., etc.)

Gilbert

The error said the error was in repeatedExecute(), can you post the content of that function? (Or was it just a typo in the function name?)

EnterTheStory (aka tolworthy)

"repeatedExecute" was just a function that I call from within the repeatedly executing part of the main script. Just to keep everything tidy. Here's the whole function:

From the global script:
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
repeatedlyCheckStatus();
repeatedlyCallHotspots();
}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


From the script headers:
import function repeatedlyCheckStatus();
import function repeatedlyCallHotspots();

From my own repeatedExecute module:
// Main script for module 'repeatedExecute'

int typeUnderMouse;   // GlobalInt 1
int hotspotTypeUnderMouse;   // GlobalInt 2 - my special exit type
int hotspotWaiting;      // GlobalInt 3
int hotspotActionWaiting;   // GlobalInt 5 ( 4 is the trigger)
Hotspot* thisHotspot;

function repeatedlyCheckStatus()
{typeUnderMouse =0;      // == eLocationNothing
if (GetLocationType(mouse.x,mouse.y) == eLocationHotspot) typeUnderMouse =1;
if (GetLocationType(mouse.x,mouse.y) == eLocationCharacter) typeUnderMouse =2;
if (GetLocationType(mouse.x,mouse.y) == eLocationObject) typeUnderMouse =3;
SetGlobalInt(1,typeUnderMouse);

hotspotTypeUnderMouse = 0;
if(typeUnderMouse ==1)      // over a hotspot?
{   hotspotTypeUnderMouse = Hotspot.GetProperty("exit"); // my special exit type
   if((hotspotTypeUnderMouse ==1)||(hotspotTypeUnderMouse ==2))
     mouse.Mode = eModeExit;
   else mouse.Mode = eModeWalkto;
}
}


function repeatedlyCallHotspots()
{   hotspotWaiting = GetGlobalInt(3);
   if(hotspotWaiting >0)   // what hotspot is waiting to execute?
  {   if(GetGlobalInt(4) >0)   // has the trigger been set?
      {      hotspotActionWaiting = GetGlobalInt(5);
            
if(hotspotActionWaiting ==1)   // 1= interact
{      generic_hotspots_interact();   // just in case there is default text to say
Hotspot[hotspotWaiting].RunInteraction(eModeInteract);   // in case there is special code
}
         
if(hotspotActionWaiting ==2)   // 1= interact
}
resetWaitingHotspot();
      }
   }

//--------------------------------------------------------------------------

function setHotspotWaiting(int whatAction)
{thisHotspot = Hotspot[GetGlobalInt(2)]   // the last object under the mouse
SetGlobalInt(3,thisHotspot);
SetGlobalInt(4,0);       // not yet triggered
SetGlobalInt(5,whatAction);
}
function triggerWaitingHotspot(int whatHotspot)
{      SetGlobalInt(4,1);                  
}
function resetWaitingHotspot()
{      SetGlobalInt(3,0);
      SetGlobalInt(4,0);
      SetGlobalInt(5,0);
      SetGlobalInt(10,-1);      // ego is not walking to anything
}
//--------------------------------------------------------------------------



Hope this makes sense!

Khris

#3
Spotted two errors:

{   hotspotTypeUnderMouse = Hotspot.GetProperty("exit"); // my special exit type

This is probably supposed to say thisHotspot.GetProperty(...
This is what causes the error. GetProperty is the non-static member, so you need an instance (thisHotspot) to access it.

Hotspot[hotspotWaiting].RunInteraction(eModeInteract);   // in case there is special code

should throw an error, too. The array is spelt with a lower-case "h": hotspot[index]

(Your code is really hard to read, btw. Why don't you start using proper indentation? It'll not only make everything tidy optically but also make our "job" here easier.)

EnterTheStory (aka tolworthy)

Thanks - you saved me there!

Quote from: KhrisMUC on Mon 10/12/2007 10:15:49
Why don't you start using proper indentation?

I do, but I remove the indentation for posting to avoid line wrapping. I use extensive indenting and commenting on every line, which then gets line wrapped if I ever post it to a forum. A single line can easily extend onto three lines. So I got in the habit of removing indents and most comments before posting. But next time I'll leave a little bit in. And learn how to format the code in smaller text.

Thanks again. Your help is very much appreciated!

Khris

You're welcome :)

Just use the code tag:
Code: ags
[*code]bla bla[*/code]  // without the *s


The font is pretty small to avoid line wrapping. AGS automatically indents everything using 2 spaces, IMO that works perfectly:

Code: ags
function repeatedlyCheckStatus() {
  typeUnderMouse =0;      // == eLocationNothing
  if (GetLocationType(mouse.x,mouse.y) == eLocationHotspot) typeUnderMouse =1;
  if (GetLocationType(mouse.x,mouse.y) == eLocationCharacter) typeUnderMouse =2;
  if (GetLocationType(mouse.x,mouse.y) == eLocationObject) typeUnderMouse =3;
  SetGlobalInt(1,typeUnderMouse);

  hotspotTypeUnderMouse = 0;
  if(typeUnderMouse ==1) {     // over a hotspot?
    hotspotTypeUnderMouse = Hotspot.GetProperty("exit"); // my special exit type
    if((hotspotTypeUnderMouse ==1)||(hotspotTypeUnderMouse ==2))
      mouse.Mode = eModeExit;
    else mouse.Mode = eModeWalkto;
  }
}

SMF spam blocked by CleanTalk