Author Topic: Behaviors of mouse.visible and/or .setasplayer  (Read 214 times)  Share 

LUniqueDan

  • Bladerunnerianism - A lifestyle, a vow, a religion
Behaviors of mouse.visible and/or .setasplayer
« on: 14 Sep 2012, 23:16 »
Hi guys.
I've got a nasty bug in my script, totally my fault but I can't really solve it.  (And it's going to be hard to explain the whole situation).

(deep breath)

When I call the function that "switch" characters (Basically a lot of status checking followed by .SetAsPlayer() ) if the mouse is over my makeshift inventory gui (Original Maniac Mansion /Zak style) the game crashes for "null pointer" reason.

(Yay ! I did it!)

My makeshift inventory is already under heavy brackets to avoid related "null pointer" issues :
(And most of it are managed in the standard Rep_execute function)

It won't work :
- If slot under the mouse == empty (and other "null string" issues)
- If the game is paused
- If the interface is hidden (like it's the case during the cutscenes / switches)
- If the mouse is not visible
- If there's a Communist uprising in Arizona


So... any clues of what it can be ?
How (when) is the Iventory windows populated when setAsPlayer() is called ?
Any clues of what can be the problem.
(I'll feel stupid if I call an artificial mouse position changing during switch)
 
Thanks a lot. (As again, sorry for the syntax)
« Last Edit: 14 Sep 2012, 23:21 by LUniqueDan »
"Debating with you is like the unlivable monstrosity of a lovechild of Dali and Aristotle. I'm tempted to put all this on a blog, for scientific reasons."

LUniqueDan

  • Bladerunnerianism - A lifestyle, a vow, a religion
Re: Behaviors of mouse.visible and/or .setasplayer (Updated)
« Reply #1 on: 21 Sep 2012, 23:24 »
Geoff ! Sorry for the late reply, thanks to have tried an answer.

(Sorry for the double post, but I just want to reformulate my problem)

1 - Is the Repeatedly Execute() from the main script an be activated Before FadeIn ? (As far as I understand AGS : never)
2 - Is the Repeatedly Execute() from the main script activated during SetAsPlayer() if performing its own task ?
3a) - What .SetAsPlayer internally does ?
3b) - In which order ?
3c) - Is there some of these tasks (like populating the inventory with the new character's possessions) are done Non_BLocking and/or AfterFadein ?

I guess this will sum up a possible path of solution.

Thanks again for the answers.
« Last Edit: 21 Sep 2012, 23:26 by LUniqueDan »
"Debating with you is like the unlivable monstrosity of a lovechild of Dali and Aristotle. I'm tempted to put all this on a blog, for scientific reasons."

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Behaviors of mouse.visible and/or .setasplayer
« Reply #2 on: 22 Sep 2012, 00:41 »
repeatedly_execute() only runs while the interface is enabled. During blocking events or fading in/out rooms, it doesn't.

I imagine SetAsPlayer()
-changes which character the player pointer points to
-if the other player is in a different room, performs a room change

Could you post your code? It's pretty much impossible to address your problem without knowing what you're doing.
We need to at least see the line in which the error occurs and the surrounding ones.

All I can say is that avoiding a null pointer error is usually really easy. Just put if (whatever != null) in front of the offending statement.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

LUniqueDan

  • Bladerunnerianism - A lifestyle, a vow, a religion
Re: Behaviors of mouse.visible and/or .setasplayer
« Reply #3 on: 06 Oct 2012, 12:04 »
Here we go :
(Took myself time to translate comments)
The bug is always on line 83 After a Set as Player() if and olny if the mouse is somewhere over my make shif inventory...
I dunno, it's really like if the Inventory is not enabled before_fadein... (But I may be blatantly wrong)

Thanks again Kris, and good luck understanding my messy code.


Code: Adventure Game Studio
  1. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5. function repeatedly_execute() {
  6.   if (IsGamePaused() == 1) return;
  7.   String wScreen = "";
  8.  
  9.  
  10. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. // TIMER FUN - CASE 1 : AIR BREATHING
  13.       if (IsTimerExpired(6))
  14.           {
  15.           player.Mess("I can't breathe.");
  16.           STATUS_CANTBREATH++;
  17.           if (STATUS_CANTBREATH > 5)
  18.               {
  19.               Black();
  20.               player.Mess("AAAAAAAAAAAAAAAAAAAAARGH.");
  21.               player.ChangeRoom(290); // Temporary Death Room
  22.               return; //(I know it's useless but it makes me feel happy)
  23.               }
  24.              
  25.            else
  26.               {
  27.               // NB : SEE ALSO Room 140
  28.               if (STATUS_Helmet == 1 && STATUS_Wet == 1)
  29.                   {
  30.                   STATUS_CANTBREATH = 0; // reset
  31.                   player.Mess("Humpf ahhhh.");
  32.                   player.Mess("I feel much better now!");
  33.                   }
  34.              
  35.               else
  36.                   {
  37.                   SetTimer(6, 120);  
  38.                   }
  39.               }
  40.           }
  41. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  42. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  43.  
  44.  
  45.  
  46.  
  47. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  48. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  49. // TIMER FUN - CASE 2 : JUNGLE REMOVAL ROUTINE
  50.         if (IsTimerExpired(8) && FLAG_JUNGLE_DISP == 1)
  51.             {
  52.             mAliens.Stop();
  53.             BlackOUT(1);
  54.             cZak.StopMoving(); // sinon c laid
  55.             Wait(60);
  56.            
  57.             //*********************
  58.             SWITCH = 124;
  59.             //*********************
  60.             player.ChangeRoom(120); // Go directly to Mayan Temple
  61.             return; //(I know it's useless but it makes me feel happy)
  62.             }
  63. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  65.  
  66.                     // ++++ STANDARD LUCASARTS MANAGEMENT ++++
  67.  
  68. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  69. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  70. // ++++ 1 - INVENTORY BUTTON ON/OFF ACCORDING TO NUMBER OF ITEMS
  71. if (gVerbs.Visible == true && mouse.Visible == true)
  72. {
  73.                                 if (hidenINV.TopItem > 0) bINV_UP.Visible = true;                                                              
  74.                                 else    bINV_UP.Visible = false;
  75.  
  76.                                 if ((hidenINV.TopItem + 4) > (hidenINV.ItemCount-1))bINV_DOWN.Visible = false;
  77.                                 else    bINV_DOWN.Visible = true;
  78.                                        
  79. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  80. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  81. // ++++ 2 - UPDATE INVENTORY LABELS
  82.  
  83.                                 if (hidenINV.ItemCount>0)       lINV_1HG.Text = hidenINV.ItemAtIndex[hidenINV.TopItem].Name;                           
  84.                                 else    lINV_1HG.Text ="";
  85.                                                
  86.                                 if (hidenINV.ItemCount>1 && (hidenINV.TopItem+1 <hidenINV.ItemCount))           lINV_2HD.Text = hidenINV.ItemAtIndex[hidenINV.TopItem+1].Name;                                         
  87.                                 else    lINV_2HD.Text ="";                     
  88.                                        
  89.                                 if (hidenINV.ItemCount>2 && (hidenINV.TopItem+2 < hidenINV.ItemCount))          lINV_3BG.Text = hidenINV.ItemAtIndex[hidenINV.TopItem+2].Name;                         
  90.                                 else  lINV_3BG.Text ="";
  91.                                                                        
  92.                                 if (hidenINV.ItemCount>3 && (hidenINV.TopItem+3 < hidenINV.ItemCount))  lINV_4BD.Text = hidenINV.ItemAtIndex[hidenINV.TopItem+3].Name;
  93.                                 else lINV_4BD.Text ="";                        
  94.     }
  95.  
  96.  
  97. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  98. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  99. // ++++ 3 - UPDATE INVENTORY LABELS COLOR + DATA ACCORDING TO MOUSE POSITION
  100. if (gVerbs.Visible == true)
  101.     {
  102.     // PUT EVERYTHING PINK BY DEFAUT
  103.     lINV_1HG.TextColor = C64Pink;lINV_2HD.TextColor = C64Pink;  
  104.     lINV_3BG.TextColor = C64Pink;lINV_4BD.TextColor = C64Pink;
  105.     lACTION.TextColor = C64Pink;
  106.  
  107.    
  108.     // LEFT COLUMN
  109.     if (mouse.x < bINV_UP.X)
  110.         {
  111.         if (mouse.y > gVerbs.Y+bINV_3BG.Y){
  112.             lINV_3BG.TextColor = C64Jaune;
  113.             wScreen = lINV_3BG.Text;}
  114.         else if (mouse.y > gVerbs.Y+bINV_1HG.Y){
  115.             lINV_1HG.TextColor = C64Jaune;
  116.             wScreen = lINV_1HG.Text;}
  117.         }
  118.    
  119.     // RIGHT COLUMN
  120.     else if (mouse.x > bINV_UP.X+bINV_UP.Width)
  121.         {
  122.         if (mouse.y > gVerbs.Y+ bINV_3BG.Y){
  123.             lINV_4BD.TextColor = C64Jaune;
  124.             wScreen = lINV_4BD.Text;}
  125.              
  126.         else if (mouse.y > gVerbs.Y+bINV_1HG.Y){
  127.             lINV_2HD.TextColor = C64Jaune;
  128.             wScreen = lINV_2HD.Text;}
  129.         }
  130.     }
  131.    
  132. //********************************************************
  133. // TO THAT POINT IF THERE'S NULL TRANSFORM IT TO ""
  134. if (wScreen == null) wScreen = ""; // THIS IS ANTI-BUG  
  135. //********************************************************    
  136.    
  137.       // ACTION LABEL COLOR : PURELY ESTHETICAL
  138.       if (mouse.y >= gActionLine.Y && mouse.y <= gActionLine.Y+gActionLine.Height)lACTION.TextColor = C64Jaune;
  139.       else lACTION.TextColor = C64Pink;  
  140.  
  141.  
  142. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  143. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  144.  
  145.  // NO PUT ON / TAKE OFF FROM ANYTHING ABOVE ACTION LINE
  146.  if ((vACTION == aPutOn || vACTION ==aTakeOff) && mouse.y < gActionLine.Y)wScreen = " ";  
  147.  
  148.  
  149.  // IF wScreen was not already fill with an inventory name - Fill it With the sceen Location
  150. if (wScreen == "")wScreen = Game.GetLocationName(mouse.x, mouse.y);  
  151.  
  152.  
  153.  // EXCEPTIOn - NO BOOK TITLE FOR ZAK
  154.  if (player.ID == cZak.ID && (player.Room == 10 || player.Room == 9))
  155.     {
  156.     if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot)
  157.         {
  158.         LeSpot = Hotspot.GetAtScreenXY(mouse.x,  mouse.y);  
  159.         if (LeSpot.GetProperty("ISBOOK") > 0)  wScreen = "books";  
  160.         }
  161.     }
  162.    
  163.    
  164.    
  165. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  166. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  167. // ++++ Update ACTION LINE  
  168.  
  169. // +++ CASE 1 - USE / GIVE  
  170. if (player.ActiveInventory != null)
  171.     {
  172.     if (vACTION == aGive)  
  173.         {
  174.         if (GetLocationType(mouse.x, mouse.y) != eLocationCharacter) wScreen ="";
  175.         lACTION.Text = String.Format("%s %s to %s",wACTION, player.ActiveInventory.Name, wScreen);
  176.         }
  177.      
  178.      // +++ AUTOMATICAL INVENTORY LAUCHES (NO "USE X WITH Y" FOR THOSE)
  179.      else if (vACTION == aUse && player.ActiveInventory == iGPS){iGPS.RunInteraction(eModeInteract);}  
  180.      else if (vACTION == aUse && player.ActiveInventory == iRemoteC){iRemoteC.RunInteraction(eModeInteract); }    
  181.      else if (vACTION == aUse && player.ActiveInventory == iMuffin) {iMuffin.RunInteraction(eModeInteract);}  
  182.      
  183.      // +++ STANDARD USE OF "USE"
  184.      else if (vACTION == aUse)  
  185.         {
  186.         lACTION.Text = String.Format("%s %s with %s",wACTION, player.ActiveInventory.Name, wScreen);
  187.         }
  188.        
  189.     // STANDARD USE OF ANY OTHER VERBS ON ITEMS
  190.     else
  191.         {
  192.         lACTION.Text = String.Format("%s %s",wACTION, player.ActiveInventory.Name);  
  193.         }
  194.     }
  195.    
  196.    
  197. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  198. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  199. // NO INVENTORY THEREFORE IT'S ON THE SCREEN
  200.  
  201. else
  202.     {
  203.     lACTION.Text = String.Format("%s %s",wACTION, wScreen);
  204.     }
  205. }
  206. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  207. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  208. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  209. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  210. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  211.  
  212.  
« Last Edit: 06 Oct 2012, 12:07 by LUniqueDan »
"Debating with you is like the unlivable monstrosity of a lovechild of Dali and Aristotle. I'm tempted to put all this on a blog, for scientific reasons."