object on in inventory?

Started by Anarcho, Mon 12/11/2007 19:36:00

Previous topic - Next topic

Anarcho

I've encountered an error on something.  What i tried to do is turn an object on after looking at an inventory object. 

I used this script:

function iNotebook_Look()
{
  object[20].Visible = true;
  Wait(150);
  object[20].Visible = false;
}


I encountered this error:

---------------------------
Adventure Game Studio
---------------------------
An internal error has occurred. Please note down the following information.
If the problem persists, contact Chris Jones.
(ACI version 3.00.958)

Error: run_text_script1: error -6 running function 'iNotebook_Look':
Error: Array index out of bounds (index: 20, bounds: 0..19)
in "GlobalScript.asc", line 179


---------------------------
OK   
---------------------------


I'm assuming it's just that the inventory window is still on and i need to turn it off somehow?  Essentially all I want to do is when you look a book in the inventory screen, a page of the book pops up for 20 seconds or so.  What am I missing?  I'm using Version 3.0.0.15

Thanks

Logan


GarageGothic

#1
No it's not your fault, it's a problem in AGS 3.0, which although supporting up to 40 objects per room actually can't handle more than 20 object indexes (0-19). This has been reported and should be fixed in the next version.

Edit: Sorry, I'm talking out my ass, the current version should support indexes up to and including 20 according to the error report. I assume this code is in the global script however, and objects are room specific. So do you actually have an object nr. 20 in the room that you're running this script in? If you're supposed to be able to look at the book in more than a single room, it would be better to use a GUI or an Overlay for the book page (GUI if it's supposed to appear in front of the inventory window).

Edit 2: In response to the other reply, if this is indeed in global script, you won't be able to use object script-o-names, since those are loaded along with the room and will give a compile error in the global script.

VK Dan

You could always try using the Script Name of your object to access it, instead of using the object array. To figure out what this is, you would need to look in the properties pane of your object.

Anarcho

Yup, this is in the global script, and I do have an object 20). 

I used the following overlay script (thanks for the suggestion, I haven't used this before:

function iNotebook_Look()
{
Overlay* myOverlay = Overlay.CreateGraphical(100, 75, 95, false);
Wait(90);
myOverlay.Remove();
}


The only problem is, that the overlay is behind the inventory screen so you can't see it.  How do you set a baseline for an overlay?  Or do i need to turn off the inventory screen somehow?

Thanks for the help, i appreciate it,

Logan


GarageGothic

Well, Overlays like Objects will always be behind GUIs, that's why I added "GUI if it's supposed to appear in front of the inventory window". But you were talking about turning off the Inventory GUI while displaying it, so that's why I suggested Overlays. Are you using the built-in inventory or a custom one? Custom ones can be turned off and on using GUI.Visible on and off, but the built-in one has its own special commands, not sure if it's possible.

If you want to show the book page in front of the inventory, create a separate GUI to display the page in, and remember to set the order of the GUIs.

Anarcho

#5
oh, i see.  i am just using the built in inventory gui. 

I'll just make a gui and use that...

EDIT: Nix, that I just tried to turn the inventory off and it worked like a charm.  Here's the final script:

function iNotebook_Look()
{
gInventory.Visible = false;
Overlay* myOverlay = Overlay.CreateGraphical(100, 75, 95, false);
Wait(90);
myOverlay.Remove();
gInventory.Visible = true;
}

worked great.  thanks!


Anarcho

One follow up question...how do I set the overlay to turn off on a mouseclick?  So when the overlay of the open book pops up, it will turn off when the player clicks the mouse?



GarageGothic

First of all, you'll have to move the declaration of the overlay ("Overlay* myOverlay;") to the top of the GlobalScript, since you'll be calling it from multiple other scripts. Also, you probably want to use PauseGame() before closing the inventory, so the game won't be running in the background of the overlay.

Then, you can put in the on_mouse_click() function:

Code: ags
if (myOverlay.Valid) {
   myOverlay.Remove;
   UnpauseGame();
   InventoryScreen();
   }

SMF spam blocked by CleanTalk