Object interaction--Script doesn't appear to run [SOLVED]

Started by HammerBlade, Sun 25/11/2007 23:40:34

Previous topic - Next topic

HammerBlade

Okay.  It would have been better to use a GUI instead of a ton of objects.  Nonetheless, I would like to know why this approach doesn't work.

I'm attempting to make a card game interface in AGS, and the method I've chosen is to have a room, filled with objects which represent areas on a table-top where cards in the game go.  Essentially, I have it set so that the initial graphic of each object is an outline of the area where the card goes ("card slots"), so when cards are dealt, the graphic of each object changes to the card that was assigned to that object.  That itself works hunky-dory.

I also have an additional object in the room, a "highlighter" (a box that fits around a card graphic), so that when a card is clicked on, the highlighter is directly over the card.

I went to edit the interactions of one of the card slots, and under the "Any click on object" trigger (or are they called events...? I digress.), I added the following script:



object[18].SetPosition(91,160);   

//   18 = The "highlighter" object
//   (91,160) = the coordinates of the card slot



I went to test the game, and it compiled fine.  However, no matter how much I clicked on the card slot, the highlighter refused to overlap the card slot. 

Aside from the fact that I've picked an overly complicated approach to the making of a card game, why doesn't this work?

Khris

In a case like this, ALWAYS put a simple Display command in there first to check if the function is run at all.
Is the object in question set to clickable? Did you check "pixel-perfect click detection"?

Btw, you can reference objects using their script-o-names (oHighlighter.SetPosition(...)). Easier and more readable than using the numbers.

HammerBlade

Let's see:

-"Pixel perfect click detection" is checked...
-A Display function has been placed both before and after the line that reads "object[18].SetPosition(91,160);", but no message is displayed upon clicking on the object.

And while it is true that it's better to use script-o-names, utilizing them also caused a compile error.  In particular, the message read:

"Type mismatch:  cannot convert 'object*' to 'int' ".

For example, rewriting the line of code like this...


object[oCard_highlighter].SetPosition(91,160);
//oCard_highlighter = the script-o-name of the card highlighter object.  (Who would have guessed it?)


...yielded the "type mismatch" error. 
???  I say again,  ???


Gilbert

If you use the o-names, you should use it like this:

oCard_highlighter.SetPosition(91,160);

Use the o-names to refer to objects directly, they're not indices. :P

HammerBlade

Hm...that explains SO much.  And it looks a lot cleaner than the way I was trying to use them.  :P Thanks!

In any case, the game still doesn't seem to want to respond to "Any click on object".   >:(

Khris

So, did you check if the object is set to be clickable?
Which cursor mode are you using?

SSH

NB. Walking cursor isn't included in "Any".!!!

Also, are you sure the highlighter isn't hidden behind it?

Try putting a Display command in the function to make sure that the code is getting erxecuted.
12

HammerBlade

(Edit:  The room this all takes place in is room 2, the designated room for the game.  I'll specifically state when I'm talking about anything outside this room.)

I've placed the highlighter object visibly in the room, and since it doesn't move from that spot after clicking on the card slot, it would seem that the card slot isn't responding to mouse clicks, so it's not under the card slot.  Even if it were, the sprite for the highlighter is a couple pixels bigger than the card slot, so it would show up underneath it anyway.

Quote from: HammerBlade on Mon 26/11/2007 00:57:52

-A Display function has been placed both before and after the line that reads "object[18].SetPosition(91,160);", but no message is displayed upon clicking on the object.



For the script listed under "any click on object" for the card slot object, I've added two display functions, one before and one after, like so:

Display("That was nuts!");
oCard_highlighter.SetPosition(91,160);   
Display("That was nuts!");                               // (For some reason, this script doesn't run, causing me to
                                                                         //wonder if the object is responding to clicks at all...)

In a script under "player enters room (before fadein)", the code "oP2_faceup1.Clickable = true;" has been written.  Placing a display function before and after this line showed that this particular script passed. 

I also put that same line of code at the beginning of "player enters room (after fadein)", just in case for some reason the "clickable" argument didn't pass before the fadein.  Even after this, the card slot remains unresponsive to clicks.  (I've used those words a lot today, "responsive" and "click", haven't I?)

"So it's unresponsive even though it's been specifically defined as responsive?  Must be a cursor issue..." 

Such was my hope, but that didn't seem to be it either.  In room 1, during "player enters room (before fadein)", a script to set the cursor is placed.  I've tried a couple of cursors now, one being the pointer, and the other being the interact cursor.  Neither of these elicit any response from the card slot object.  I've even added some script under "interact with object" for the card slot, but a click with the interact cursor doesn't get the object to run the script.  Of course, the script for "any click on object" doesn't run either.

I hope I've been thorough enough in my description.  Any glaring oversights on my part? :-X

Pumaman

Out of interest, can you try turning off Pixel Perfect Click Detection and see if it works then?

Khris

I'd name the object and add an "@OVERHOTSPOT@" label on a GUI to make sure the mouse is above the object during a click.
Oh, and, out of curiousity: you didn't remove ProcessClick from on_mouse_click, right?

HammerBlade

uh, wut aer thes label thingz ur taking abot?  ...oh rite, i haev a manuel...*reads* oh, TAHTS how u put sum1's hp in rpgs!

Ahem.  Seriously though...

So, first I tried Pumaman's suggestion of turning pixel-perfect detection off, but sadly this didn't change anything.

Then, I threw in an @OVERHOTSPOT@ label into the room.  In addition, I drew in a hotspot in the same general area where the card slot is, so when my mouse moved over it, the @OVERHOTSPOT@ label would indicate that was so.  Much to my surprise, the label remained blank when my mouse was over the hotspot!

Finally, I double-checked the global script to make sure ProcessClick was still present in the on_mouse_click function, and it was still there:



#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  {
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
    {
    }
  else if (button == eMouseLeft)
    {
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
    }
  else // right-click, so cycle cursor
    {   
    mouse.SelectNextMode();
    }
  }
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE



Khris

Contrary to the naming, @OVERHOTSPOT@ will show objects and characters, too.
The only thing I can think of that's left is a transparent GUI covering the whole area.
If that GUI is set to clickable, it'll catch all clicks.
Put Display("click"); above ProcessClick. If that shows, check all GUIs.

SSH

Sounds like it has got to the point where you need to upload the game folder so that people can try things directly...
12

Pumaman

Yeah, if your game is small enough it might be a good idea to upload it so that we can take a look. It's probably something really obvious that we're forgetting.

HammerBlade

 :o >:(

...KhrisMUC... >:( you...

...hit the nail on the head.  As such, you are a freaking GENIUS! ;D

The problem was that a GUI, which I had thrown in to display players HP, was covering the whole room.  As you suggested, the only element which could detect clicks was this GUI, because it overlapped everything else.

I removed that GUI and tested the room again by clicking on the card slot to see if the card highlighter would move over it as a result.  Sweet success!

Now all I gotta do is figure out a good score display method, and get the highlighter to appear over the card slots...ah well, at least those are work-around-able issues.

Thanks everyone for all the help!

Khris


SMF spam blocked by CleanTalk