Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Kinoko on Fri 16/04/2004 15:09:52

Title: Argh! Weird inventory error
Post by: Kinoko on Fri 16/04/2004 15:09:52
All of a sudden, this new error has turned up in my game that won't allow me to progress. It always worked before but I haven't changed this particular script at all.

Basically, I need to give 4 items (in any order) to a character. This error now appears after giving ANY of these 4 items to the character. It seems to conk out at any of the LoseInventory lines. Here's one of the items' script.

if (character[EGO].activeinv == 23) {
if (Go()==1) //Start going to the object and if the player
   {      // does not abort do the following:
FaceCharacter (EGO, DUST);
FaceCharacter (DUST, EGO);
DisplaySpeech (EGO, "Here you go.");
SetCharacterView (EGO, 20);
Wait(10);
SetCharacterView (DUST, 87);
Wait(20);
LoseInventory (23);  //Game will crash here
ReleaseCharacterView (EGO);
Wait(10);
ReleaseCharacterView (DUST);
SetGlobalInt (17, 1);
}  
}

The error I get comes with the number 2.60.693. It says, "GetInvName: Invalid inventory item specified" and points to this line of script in the Global Script:

/**/     GetInvName(character[GetPlayerCharacter()].activeinv ,usedinvname);

Here's the surrounding script:

/**/function unhandled_event(int xxx, int yyy){/////////////////////////////Unhandled Event//////////////Unhandled Event
/**/  int type=GSloctype;//GetLocationType(mouse.x,mouse.y);
/**/  string locationname,usedinvname;//,buffer;
/**/  StrCopy(locationname,GSlocname);
/**/  RemoveExtension(locationname);
/**/  if (GetInvAt(mouse.x,mouse.y)>=0) type=4;
/**/  if (GSagsusedmode==4){
/**/     GetInvName(character[GetPlayerCharacter()].activeinv ,usedinvname);
/**/     RemoveExtension(usedinvname);
/**/    if (type>0) type+=4;
/**/  }
/**/  if (GSagsusedmode!=9 && type!=0 && IsGUIOn(MAPS)==0){
/**/  

I can't make any sense of it. The inventory numbers are all correct.
Title: Re:Argh! Weird inventory error
Post by: SSH on Fri 16/04/2004 15:32:05
I think the problem is when you are still in GIVE mode, but there is no longer an inventory item selected (so player.activeinv=-1) -1 is  an invalid argument for GetInvName, so...

An immediate workaround is to change the global script to:
/**/ if ((GSagsusedmode==4) && (character[GetPlayerCharacter()].activeinv>=0)){
/**/ GetInvName(character[GetPlayerCharacter()].activeinv ,usedinvname);
/**/ RemoveExtension(usedinvname);
/**/ if (type>0) type+=4;
/**/ }

LoseInventory updates activeinv, I believe, but why is unhandled_event being called?
Title: Re:Argh! Weird inventory error
Post by: Kinoko on Fri 16/04/2004 15:41:32
I have absolutely no idea.

If it helps, here's the entire script:

 // script for character38: Use inventory on character
if (character[EGO].activeinv == 23) {
if (Go()==1) //Start going to the object and if the player
   {      // does not abort do the following:
FaceCharacter (EGO, DUST);
FaceCharacter (DUST, EGO);
DisplaySpeech (EGO, "Here you go.");
SetCharacterView (EGO, 20);
Wait(10);
SetCharacterView (DUST, 87);
Wait(20);
LoseInventory (23);
ReleaseCharacterView (EGO);
Wait(10);
ReleaseCharacterView (DUST);
SetGlobalInt (17, 1);
}  
}

else if (character[EGO].activeinv == 24) {
if (Go()==1) //Start going to the object and if the player
   {      // does not abort do the following:
FaceCharacter (EGO, DUST);
FaceCharacter (DUST, EGO);
DisplaySpeech (EGO, "There's the umbrella.");
SetCharacterView (EGO, 20);
Wait(10);
SetCharacterView (DUST, 87);
Wait(20);
LoseInventory (24);
ReleaseCharacterView (EGO);
Wait(10);
ReleaseCharacterView (DUST);
SetGlobalInt (18, 1);
}
}

else if (character[EGO].activeinv == 25) {
if (Go()==1) //Start going to the object and if the player
   {      // does not abort do the following:
FaceCharacter (EGO, DUST);
FaceCharacter (DUST, EGO);
DisplaySpeech (EGO, "Hurrah!");
DisplaySpeech (DUST, "Ah, yes, we'll soon be out of here.");
DisplaySpeech (EGO, "I told you, I'm staying here.");
DisplaySpeech (DUST, "Yes, of course.");
SetCharacterView (EGO, 20);
Wait(10);
SetCharacterView (DUST, 87);
Wait(20);
LoseInventory (25);
ReleaseCharacterView (EGO);
Wait(10);
ReleaseCharacterView (DUST);
SetGlobalInt (19, 1);
}
}

else if (character[EGO].activeinv == 7) {
if (Go()==1) //Start going to the object and if the player
   {      // does not abort do the following:
FaceCharacter (EGO, DUST);
FaceCharacter (DUST, EGO);
DisplaySpeech (EGO, "I hope you appreciate this.");
SetCharacterView (EGO, 20);
Wait(10);
SetCharacterView (DUST, 87);
Wait(20);
LoseInventory (7);
ReleaseCharacterView (EGO);
Wait(10);
ReleaseCharacterView (DUST);
SetGlobalInt (20, 1);
DisplaySpeech (DUST, "It's isn't royal blue but... eh, close enough.");
}  
}

if ((GetGlobalInt(17) == 1) && (GetGlobalInt(18) == 1) && (GetGlobalInt(19) == 1) && (GetGlobalInt(20) == 1)) {
DisplaySpeech (DUST, "Well, it looks like we have all the things we need.");
//bunch of stuff happens here...
DisplaySpeech (EGO, "Maybe I'll just stand here for awhile.");

}

else Unhandled();  
Title: Re:Argh! Weird inventory error
Post by: SSH on Fri 16/04/2004 15:49:48
Quote from: Kinoko on Fri 16/04/2004 15:41:32

else Unhandled();  


You're elsing the wrong if!

The else Unhandled should go before the
if ((GetGlobalInt(17) == 1) && (GetGlobalInt(18) == 1) && (GetGlobalInt(19) == 1) && (GetGlobalInt(20) == 1)) {
line

Title: Re:Argh! Weird inventory error
Post by: Kinoko on Fri 16/04/2004 16:09:19
D'oh! Thanks -_-