Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Knox on Wed 16/09/2009 23:26:17

Title: TopItem problem (SOLVED)
Post by: Knox on Wed 16/09/2009 23:26:17
Hi guys,

This is what Im trying to accomplish:
I simply want to hide/show the scroll arrows in the inventory depending on if a number of objects are in my inventory. Ive checked this thread, and it works partly...something is missing!

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=26364.0

This is what I did (when you click on the iconbar's inventory button, this function gets called):


function show_inventory_window ()
{  
 invCustomInv.TopItem = 0;
 gInventory.Visible = true;
 // switch to the Use cursor (to select items with)
 mouse.Mode = eModeInteract;
 mouse.UseModeGraphic(eModePointer);
 // But, override the appearance to look like the arrow

 if (invCustomInv.ItemCount <= 12)
 {
   btnInvDown.Visible=false;
   btnInvUp.Visible=false;    
 }
 else
 {
     if (invCustomInv.TopItem > 0)
     {
       btnInvUp.Visible = true;
       btnInvDown.Visible=true;
     }
     else
     {
       btnInvUp.Visible = false;
       btnInvDown.Visible=true;
     }
   
 }

}


When I get more than 12 items in the inventory, my down cursor shows up like it should, however, once i press it to scroll down, the up arrow doesnt appear, it stays hidden...I dont understand whats missing...:P
 

EDIT:

I placed the script above in my rep_exec and it now works...One question, is it "bad" to have lots of lines in the rep_exec function? Since everything is run all the time, if you haves lots of code in there it can get "slow", right?

What is considered "insane" amount of lines to be found in that function? As in, whats the average for a full length game...?

Thanks!
Title: Re: TopItem problem (scroll arrows appear/disppear)
Post by: Gilbert on Thu 17/09/2009 01:47:41
This function only corresponds to the instance when the inventory interface is shown (in fact the middle 'if (invCustomInv.TopItem > 0)' part of the if nest is unnessary since when the GUI is just brought up you have set  Topitem to 0. This is not related to your problem though).

The problem probably lies in the script which got called when you click on the 'down' button. You may check that part (or post it here) instead.
Title: Re: TopItem problem (SOLVED)
Post by: Khris on Thu 17/09/2009 02:50:29
I'd put the part that updates the buttons' visibility in a separate function and call that at the end of the buttons' OnClick functions and in on_event / eEventAdd/LoseInventory.
Title: Re: TopItem problem (SOLVED)
Post by: Knox on Thu 17/09/2009 17:42:09
Thanks guys...this is what I did, and I have exactly what I wanted!



function SetInvScrollArrows()
{
    if (invCustomInv.ItemCount <= 12)
    {
      btnInvDown.Visible=false;
      btnInvUp.Visible=false;   
    }
    else
    {
      if (invCustomInv.TopItem > 0)
      {
        btnInvUp.Visible = true;
        btnInvDown.Visible=true;
      }
      else
      {
        btnInvUp.Visible = false;
        btnInvDown.Visible=true;
      }
       
    }     
}


function btnInvUp_Click(GUIControl *control, MouseButton button)
{
//  invCustomInv.ScrollUp();
  mouse.Mode = eModePointer;
  invCustomInv.SmoothScrollPrev(eScrollVertical);
  SetInvScrollArrows();
}

function btnInvDown_Click(GUIControl *control, MouseButton button)
{
//  invCustomInv.ScrollDown();
  mouse.Mode = eModePointer;
  invCustomInv.SmoothScrollNext(eScrollVertical);
  SetInvScrollArrows();
}



PS Khris: The part about "on_event / eEventAdd/LoseInventory"...I guess when I have some function that does that, I add "SetInvScrollArrows()" to the end, right?
Ill look up those functions to see what  they are in the manual right now.

Thanks :)

Title: Re: TopItem problem (SOLVED)
Post by: Khris on Thu 17/09/2009 18:23:55
Yes, all you'd need to do is add this to the global script:

void on_event (EventType event, int data) {
  if (event == eEventAddInventory || event == eEventLoseInventory)
    SetInvScrollArrows();
}
Title: Re: TopItem problem (SOLVED)
Post by: Knox on Fri 18/09/2009 17:40:07
Ok ,so I added  this:


void on_event (EventType event, int data)
{
  if (event == eEventAddInventory || event == eEventLoseInventory)
  {
    SetInvScrollArrows();
  }
}


Now, just so I understand fully...

If either one of these events happen, run the function "SetInvScrollArrows". That I understand. What is a "void"...I search the manual without luck. How does this work, and why use it in this case?

Im guessing its not the same as a function...as in, you dont have to call it specifically to get it to run? Is it like a special function where it listens to see if either of those 2 conditions are met, it runs itself?

Title: Re: TopItem problem (SOLVED)
Post by: NsMn on Fri 18/09/2009 17:48:58
It's the "modern" function, you use it for a function that not returns a value. You can use function instead, but then you would get stoned to death by Khris.
Title: Re: TopItem problem (SOLVED)
Post by: Knox on Fri 18/09/2009 18:13:00
hAHA! OK....heh!  :P

I got one last question for today...I simply just want to have my mouse cursor change to the pointer when its lower than 740 pixels...so I placed this in my rep_exec:

  if (mouse.y >= 740)
  {
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode = eModePointer;
  }


This works...UNLESS I have a hotspot on the bottom of my screen setup with a script function that checks if there is a text property ("Exit") and changes the cursor to an exit cursor...The, when I go below 740 pixels in mouse.y, it changes to the pointer, but when I go through the hotspot, it changes to the exit cursor (which is ok), but when I leave the hotspot, instead of going to the last used cursor, it goes to the pointer cursor.

Here is the hotspot function (from another thread:http://www.adventuregamestudio.co.uk/yabb/index.php?topic=36984.0)


function check_cursor()
{
  if (GetLocationType(mouse.x,mouse.y)==eLocationHotspot)
  {
    Hotspot* h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    if (h.GetTextProperty("Exit") == "Top")
    {
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModeWalkto;
      mouse.UseModeGraphic(eModeExitTop);
    }
    else if (h.GetTextProperty("Exit") == "Bottom")
    {
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModeWalkto;
      mouse.UseModeGraphic(eModeExitBot);
    }
    else if (h.GetTextProperty("Exit") == "Left")
    {
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModeWalkto;
      mouse.UseModeGraphic(eModeExitLeft);
    }
    else if (h.GetTextProperty("Exit") == "Right")
    {
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModeWalkto;
      mouse.UseModeGraphic(eModeExitRight);
    }
    h = null;
  }
}


What am I doing wrong, or better yet, what is missing? I think there are 2 instances of "saveCurosrUntilItLeaves", so Im not sure how to bypass one of them when the cursor travels through the hotspot AND below mouse.y 740 pixels.
Title: Re: TopItem problem (SOLVED)
Post by: NsMn on Fri 18/09/2009 18:17:55
My guess is that's the SaveCursorUntilItLeavesFunction... try to replace it with a
int savemouse=Mouse.Mode;
and another line after the brace from the mouse.y-if-construction:
else mouse.Mode=savemouse;

SHOULD work.
Title: Re: TopItem problem (SOLVED)
Post by: Khris on Fri 18/09/2009 18:30:03
To elaborate a bit: "function" is just a substitute for "int".
So when you write your own function using the function keyword, what the compiler "sees" is:

int MyFunction(...) {
  ...
}


In theory, this is only necessary if the function actually returns an int at the end.
If a function isn't supposed to return anything, this is signified using the void keyword.
I've accustomed myself to using void where appropriate, so it ended up in here :)
Title: Re: TopItem problem (SOLVED)
Post by: Knox on Tue 22/09/2009 01:47:48
Interesting...very interesting!

Well thanks guys, its all working like it should now!

:)