Is there a The Dig template to be found anywhere?

Started by daryl, Mon 09/04/2007 11:26:44

Previous topic - Next topic

SupSuper

To add code such as "if double_click over hotspot X, trigger player.ChangeRoom();", you just create an interaction on hotspot X when it's clicked, and have something like:
Code: ags

import double_click; // Your global script will need a "export double_click;" on the end, too

function hotspot1_a()
{
  if (double_click)
    player.ChangeRoom();
}
Programmer looking for work

daryl

#21
Thanks a bunch man, that worked actually great, after some more research. I had to put the int double_click; up in the global script before any sectionstarts to be able to export it. I added the export double_click; like you said, and used your code in the room script but I had to add int before double_click to be able to import it. Also, even though I renamed the script-O-Name to hPortalLeft it still had to be hotspot3_a() for AGS to recognize it, a bit odd?

Anyways, the function does the job perfectly now, but another issue appeared with the WaitMouseKey code, the cursor dissappear when clicking the mouse button for about a second or so, whether I release the button or not. The "i" sprite for inventory in the left bottom corner (as in The Dig) behaves just like the cursor and dissapears in sync with it.

Code is as follows:

Code: ags

//double_click function

if (button==eMouseLeft) {
//Mouse.UseModeGraphic(eModeInteract);
double_click = WaitMouseKey(8);
mouse.IsButtonDown(eMouseLeft);
//Mouse.UseDefaultGraphic();


Anyone knows why? Thanks!

Ashen

For the cursor - it looks like you've commented out the line that should stop that from happening. Remove the '//' from the mouse.UseGraphic line and the UseDefaultGraphic one.
For the GUI, what's your 'When interface disabled' setting ('General Settings' window)? The template default is 'GUIs turn off' - meaning it's perfectly normal for that GUI to vanish during a Wait command. If you don't want that to happen, change the setting.
I know what you're thinking ... Don't think that.

Khris

What exactly does the
mouse.IsButtonDown(eMouseLeft);
line in your code do?
mouse.IsButtonDown() will return whether the button is pressed or not, so calling it alone (and not inside if(..)) is pointless.

daryl

#24
*edit*
I checked my "wait" cursor and it was transparent, so what I did was changing that to the interact sprite and everything worked as it should. Weird though because I thought the Mouse.UseModeGraphic(eModeInteract); would override the 'wait' cursor. Anyways, I'm pleased with the results!

---------------------------------------------------------------------------------------------------------------------------------------
Ashen: I commented those lines out because there were no change in behaviour. I must be missing something.. The other GUI part you mentioned worked like a charm, thanks a lot.

KrisMUC: Good question.. I think I let that part loose from another line but I put it back so here's the current somewhat less messy code-

Code: ags

if (button==eMouseLeft) {
Mouse.UseDefaultGraphic();

double_click = WaitMouseKey(8)*mouse.IsButtonDown(eMouseLeft);
Mouse.UseModeGraphic(eModeInteract);


	}
}

The Mouse.UseDefaultGraphic(); and the Mouse.UseModeGraphic(eModeInteract); doesn't do anything I'm afraid :(

I'm lost.

daryl

#25
*edit*
So I've found a way of changing item sprite when clicking on the item in the inventory. I just need to have that function triggered when it is over another item/ object/ hotspot/ character etc.

I have in repeatedly execute:
Code: ags

if (player.ActiveInventory != null) {
  mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
}


And in my test item (the key) I made a custom property (named Outline), with Number property, so that I can set what sprite number it should change into (another sprite, same look but with an outline). How do I define that I want it to change whenever I have the item over other objects? I suppose I need to use the code under repeatedly execute somewhere else and with more defined conditions..

Thanks!

-------------------------------------------------------------------------------------------------------------------------

//obsolete
(Ok, so the only thing left for now is to script how to have the items outlined with a color whenever the item used is on another item (in or outside GUI) or on hotspot/ character etc. I've looked for quite some time on both manual and forum but no luck. I guess it's just a sprite switch, but didn't find one that fit when using the interaction editor on any of the items. Anyone knows what to do? Thanks a bunch!)

Khris

Code: ags
Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);
if (o!=null) ... 

Same for hotspots and chars.

daryl

Sorry I can't solve this by my own. Was that the complete code? Where does it go?
I tried putting it into rep ex, but it made no difference.
Thanks..

SupSuper

Khris' code checks if the cursor is over an object. You just put it in rep_ex and then add whatever you want to do when the cursor is over an object. And you can modify it for hotspots, characters, etc, by replacing "Object".
Programmer looking for work

daryl

#29
thanks for your help and time guys..

this is what I've done- I put KrisMUC's code into rep ex along with my definition of what should happen-

Code: ags


	Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);
	
	if (o!=null) {
	mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
}


I gave my items this Outline property, which is a Number property. I try it on the key item. The way it works now is that when I use the key on an object in the scene, the cursor changes into another sprite irrerversably (which I define as sprite number in the Custom Property/ Outline), but that's not what I want. I need it to change when on mouse over the objects, and switch back to the original sprite whenever I'm not over another object.. I guess I'm doing something wrong..

Any help is greatly appreaciated.. thanks.

SupSuper

#30
Iirc, to restore the cursor you need SaveCursorUntilItLeaves:
Code: ags

Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);
	
	if (o!=null) {
	mouse.SaveCursorUntilItLeaves();
	mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
}


If that doesn't work, use this:
Code: ags

Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);
	if (o!=null) {
	mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
	} else {
	mouse.ChangeModeGraphic(eModeUseinv, old_slot); // Replace "old_slot" with the original sprite number for the cursor (when not over an object)
	}
Programmer looking for work

daryl

#31
*edit*

- I got rid of one "null pointer referenced" error, made a condition so that it didn't try to change cursor if the mouse mode was anything else but eModeUseInv

- it works great for objects and characters

issues remaining:

1. When I apply the functions for the inventory items, the items change as soon as I've clicked them, it doesn't seem to look for another item, and it keeps the sprite even when hovering over empty GUI slots. When I move the item cursor outside the GUI it acts as it should. As if the GUI was treated as an object or item itself?

2. I still get a  "null pointer referenced" error when I try to apply this code to hotspots as well. Any idea why?

Here is the current code:

Code: ags

//Cursors -> outlined sprites when over interaction objects
if (mouse.Mode == eModeUseinv)	{ //So that the function don't apply to interact or walk cursors etc.

InventoryItem*i=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

if (i!=null) {
  
mouse.SaveCursorUntilItLeaves();
mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property

	}

//Change cursors only when outside the GUI
	
if ( GUI.GetAtScreenXY( mouse.x, mouse.y ) == null ) {

Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);

if (o!=null) {
  
mouse.SaveCursorUntilItLeaves();
mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property

	}

Character*c=Character.GetAtScreenXY(mouse.x, mouse.y);

if (c!=null) {
  
mouse.SaveCursorUntilItLeaves();
mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property

	}
}
}
}


Thanks a lot!




----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

SupSuper that worked great! I don't think I could use the 2nd code because then all cursors would get the same default "old_slot", but the first one was just the way I wanted. Thanks a ton!

I had to uncheck the "pixel perfect click detection" or else the cursor didn't change until in the center of the sprite or something like that..

However, I get a "null pointer referenced" error when I use the same code for either hotspots or inventory items, or when using the interact cursor above an object

Here is what it looks

Code: ags

Hotspot*h=Hotspot.GetAtScreenXY(mouse.x, mouse.y);

if (h!=null) {
mouse.SaveCursorUntilItLeaves();
mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
}

InventoryItem*i=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

if (i!=null) {
mouse.SaveCursorUntilItLeaves();
mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
}

Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);

if (o!=null) {
mouse.SaveCursorUntilItLeaves();
mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
}

Character*c=Character.GetAtScreenXY(mouse.x, mouse.y);

if (c!=null) {
mouse.SaveCursorUntilItLeaves();
mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
}

Khris

#32
Use this:
Code: ags
Hotspot*h=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
InventoryItem*i=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);
Character*c=Character.GetAtScreenXY(mouse.x, mouse.y);

if ((h!=null || i!=null || o!=null || c!=null) && player.ActiveInventory!=null) {
  mouse.SaveCursorUntilItLeaves();
  mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); // Or whatever you named the property
}

And tell us the line the error occurs in...

EDIT: My guess is that calling GetProperty while ActiveInventory==null throws the error, updated code to reflect that.

daryl

#33
thanks for your suggestions KhrisMUC!

If I exchange my code to the one you suggested I get the following behaviour:

-When clicking on an inventory item it turns directly into the outlined sprite (same as before), but it also doesn't switch back even if I move it outside the GUI.

-If I remove the hotspot function out of the code, I get the same behaviour as I had before- but with cleaner code (which is good). If I remove the InventoryItem function and keep the Hotspot function, the items in the inventory still switch when clicking on them inside the GUI- and there's no Hotspot close by.

-I don't get any null pointer ref error any longer though and for that I'm very greatful.

Still there is something weird going on with the inventoryitems and hotspots :/

daryl

Anyone have any idea how I could solve the problem in my previous reply? All help is welcomed.

Thanks!

Khris

InvItems:
From the manual regarding SaveCursorUntilItLeaves()
QuoteSaves the current mouse cursor, and restores it when the mouse leaves the current hotspot, object or character.
So this unfortunately won't work with InvItems.

Hotspots:
From the manual regarding Hotspot.GetAtScreenXY()
QuoteIf there is no hotspot there, or if invalid co-ordinates are specified, the Hotspot* representing hotspot 0 will be returned.
That's something I always forget; the reason for this: hotspots are drawn by the user and handled as bitmap by AGS.
Solution: if (h.ID>0)

Try:
Code: ags
  Hotspot*h=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  InventoryItem*i=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);
  Character*c=Character.GetAtScreenXY(mouse.x, mouse.y);

  if (player.ActiveInventory!=null) {
    if (h.ID>0 || o!=null || c!=null || i!=null)     // hotspot code updated
      mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); 
    else 
      mouse.UseDefaultGraphic();
  }

daryl

the hotspot mouseover code worked perfect, thanks a lot Khris, much appreciated.

I'll see what else can be done with the inventory items.
thanks again.

Khris

The new code should deal with both issues, does it still fail with InvItems?

daryl

The problem seemed to be the mouse.UseDefaultGraphic(); which didn't work, so the cursor never went back to the original inventory sprite when if once had changed. I did try another thing instead, I created a new custom property for the cursor, named it "NoOutline" which defined the cursor sprite in the original state, and called it back again, and this worked great!

Code: ags

Hotspot*h=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  InventoryItem*i=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  Object*o=Object.GetAtScreenXY(mouse.x, mouse.y);
  Character*c=Character.GetAtScreenXY(mouse.x, mouse.y);

  if (player.ActiveInventory!=null) {
    if (h.ID>0 || i!=null || o!=null || c!=null)	{     
      mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("Outline")); 
		}	else {
			mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("NoOutline")); 
		//Mouse.UseDefaultGraphic();
		
	}
	


thanks!

daryl

#39
So, getting pretty close to where I want thanks to you guys. Thanks for your patience with me!

One of the things left is, that when I have an Inventory cursor active, and click on the screen so that an action triggers (walk, use etc) it switches temporarily back to the Interact cursor for a second, then back to the Inventory cursor again. Is there any way the Inventory cursor can become/ replace the action cursor whenever the inventory one is active?

I thought of something (probably far-fetched) like this (in on_mouse_click)

Code: ags

if ((mouse.Mode==eModeUseinv)	&& (button==eMouseLeft))	{
	  mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.GetProperty("NoOutline"));   


And it doesn' t do anything. I tried to find a thread like this but hard to know what to search for.

Many thanks /D

SMF spam blocked by CleanTalk