Author Topic: Point & Click (click events)  (Read 12001 times)

0 Members and 4 Guests are viewing this topic.

Offline MusicallyInspired

Point & Click (click events)
« on: January 24, 2012, 12:53:24 PM »
Cloudee, this is moreso directed to you, since you created a viable point & click interface already.

I picked up my old point & click SCI template I was working on ages ago and I've been trying to refine it for fun. I don't mean it as way to replace yours or anything since it works swimmingly, I'm just doing this for practice.

I'm having a problem handling interactions with objects. When I click on an object or hotspot with a certain action the proper message comes up, however if I keep the cursor over the hotspot and click to remove the Print message, it comes up again as if I've clicked on the hotspot again (which technically I have). How did you go about designing interactions to keep this from happening?


Brass Lantern Prop Competition

Offline Collector

Re: Point & Click (click events)
« Reply #1 on: January 24, 2012, 03:16:35 PM »
I know that this is more of something for Cloudee, but do you have a global script to dismiss a dialog box on click if one exists? Doesn't a global script get called first over a room script?
KQII Remake Pic

Offline gumby

Re: Point & Click (click events)
« Reply #2 on: January 24, 2012, 05:39:18 PM »
It seems like this should be handled within the act of printing, in a similar way that other events should be suspended when a print dialog is open (like a timer or animation taking place on the screen)?
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline MusicallyInspired

Re: Point & Click (click events)
« Reply #3 on: January 25, 2012, 11:19:49 PM »
Yeah, I don't understand why it keeps popping up. I created this template based on the initial rudimentary P&C system King Graham (I think that's what he called himself) made a number of years ago. He has a switch statement in User.sc which handles interactions with ego and this problem doesn't happen. My switch statement is in the room script. His code does have a pEvent:claimed(TRUE) declaration at the end of each case, though. I tried that and nothing happened. Though, my code is in the doIt method and not in the handleEvent method.
Brass Lantern Prop Competition

Offline gumby

Re: Point & Click (click events)
« Reply #4 on: January 26, 2012, 08:08:40 AM »
Haven't looked into event handling much, but it sounds like you are near a solution.  I would agree with collector that it probably should be in a global script instead of a room script, but that shouldn't stop it from working.  Any chance you could post some sample code?
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Point & Click (click events)
« Reply #5 on: January 26, 2012, 03:49:11 PM »
Ok so as far as the repitition, undoubtedly the problem is occurring because it is in the doit method instead of the handleEvent method. As long as your ceryain you have the event claimed true inserted into every interaction. if you move the code into the handleevent method that problem should go away. As far as clicks on ego go, it is always going to be a matter of priority. If the click on ego code is in a global, or region script then the roomscript code will trump the clicks on ego. For instance, if you have a door in the roomscript and ego in a global and ego is in front of the door when you click on him, it will register as a click on the door because the roomscript has priority. furthermore, if you have a tree and ego in the roomscript, whether ego is in front or behind the tree, the script will only be run as far as whichever interaction is coded first assuming you are using if/else  statements. if you just use if and not elses, you may get both responses which is equally undesirable.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline MusicallyInspired

Re: Point & Click (click events)
« Reply #6 on: January 28, 2012, 09:25:57 AM »
Thank you! I'm not sure why I felt it was necessary to put the code in doIt instead of handleEvent. I'm sure that's the problem. I'll give it a shot. Good notes about ego and global commands too. Thanks muchly.
Brass Lantern Prop Competition

Offline MusicallyInspired

Re: Point & Click (click events)
« Reply #7 on: January 28, 2012, 03:09:10 PM »
Sorry! Apparently I have a bad memory. I actually did put the code in the room's handleEvent method! I'm not sure why it's reacting this way, though.

What I did was I made a region the runs the iconbar which is loaded into every room script. The code I put in ITS doIt method was the code to make the icon bar appear and disappear based on if the cursor is on top of its area or not. But that doesn't have anything to do with the room interactions which is why it's confusing me. I can provide the code if it helps.
Brass Lantern Prop Competition

Offline Cloudee1

Re: Point & Click (click events)
« Reply #8 on: January 29, 2012, 08:40:23 PM »
Sounds like seeing the code will be needed.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline MusicallyInspired

Re: Point & Click (click events)
« Reply #9 on: February 11, 2012, 12:47:24 PM »
Sorry, I completely forgot about this! Here is the template game as it is now. PNC Iconbar Template. And here's some of the scripts I put together and some edited from King Graham's original PNC template game.

Here's a screenshot as well of what it looks like.


Icon bar region script (CursorMenu.sc):
Code: [Select]
/******************************************************************************/
(include "sci.sh")
(include "game.sh")

(script 201)

(use "controls")
(use "cycle")
(use "feature")
(use "game")
(use "main")
(use "obj")

(local

    myEvent
    IconbarShowing = FALSE
    selected
)
(instance public cursorMenu of Rgn
    (properties)
    (method (init)
     (WalkButton:init()hide())
     (LookButton:init()hide())
     (UseButton:init()hide())
     (TalkButton:init()hide())
     (InvButton:init()hide())
       (ObjectButton:init()hide())
     (SaveButton:init()hide())
     (LoadButton:init()hide())
     (QuitButton:init()hide())
)
/*Hide and Show Icon bar based on mouse position */    
    (method (doit)
        (super:doit)
        (= myEvent Event:new(evNULL))
  
        (if(< (send myEvent:y) 29) // If mouse is in icon bar area
         (if(not selected)
         (self:ShowIconbar())
         (SetCursor(gNormalCursor HaveMouse()) = gCurrentCursor gNormalCursor)
)(else
(self:HideIconbar())
)
)(else   // If mouse is not in icon bar area
(self:HideIconbar())
(if(<> gCurrentCursor gCurrentAction and < gCurrentAction 5)
SetCursor(gCurrentAction HaveMouse())
)(else
(if(<> gCurrentCursor gCurrentObject and == gCurrentAction 5)
SetCursor(gCurrentObject HaveMouse())
)
)
= selected FALSE
)
        (send myEvent:dispose())
    )
    /*Icon button actions */    
    (method (handleEvent pEvent)
     (super:handleEvent(pEvent))
 
     (if(==(send pEvent:type())evMOUSEBUTTON)
         (if (IconbarShowing)
         (if((> (send pEvent:x) (WalkButton:nsLeft))and
                     (< (send pEvent:x) (WalkButton:nsRight))and
                     (> (send pEvent:y) (WalkButton:nsTop))and
                     (< (send pEvent:y) (WalkButton:nsBottom)))
                    
                 = selected TRUE
                 (WalkButton:cel(1))
                 = gCurrentAction 1
                 SetCursor(gCurrentAction HaveMouse())
                
                 (self:HideIconbar())
                 (send pEvent:claimed(TRUE))
)
(if((> (send pEvent:x) (LookButton:nsLeft))and
                     (< (send pEvent:x) (LookButton:nsRight))and
                     (> (send pEvent:y) (LookButton:nsTop))and
                     (< (send pEvent:y) (LookButton:nsBottom)))
                    
                 = selected TRUE
                 (LookButton:cel(1))
                 = gCurrentAction 2
                 SetCursor(gCurrentAction HaveMouse())
                
                 (self:HideIconbar())
                 (send pEvent:claimed(TRUE))
)
(if((> (send pEvent:x) (UseButton:nsLeft))and
                     (< (send pEvent:x) (UseButton:nsRight))and
                     (> (send pEvent:y) (UseButton:nsTop))and
                     (< (send pEvent:y) (UseButton:nsBottom)))
                    
                 = selected TRUE
                 (UseButton:cel(1))
                 = gCurrentAction 3
                 SetCursor(gCurrentAction HaveMouse())
                
                 (self:HideIconbar())
                 (send pEvent:claimed(TRUE))
)
(if((> (send pEvent:x) (TalkButton:nsLeft))and
                     (< (send pEvent:x) (TalkButton:nsRight))and
                     (> (send pEvent:y) (TalkButton:nsTop))and
                     (< (send pEvent:y) (TalkButton:nsBottom)))
                    
                 = selected TRUE
                 (TalkButton:cel(1))
                 = gCurrentAction 4
                 SetCursor(gCurrentAction HaveMouse())
                
                 (self:HideIconbar())
                 (send pEvent:claimed(TRUE))
)
(if((> (send pEvent:x) (InvButton:nsLeft))and
                     (< (send pEvent:x) (InvButton:nsRight))and
                     (> (send pEvent:y) (InvButton:nsTop))and
                     (< (send pEvent:y) (InvButton:nsBottom)))
                    
                    = selected TRUE
                    (InvButton:cel(1))
                    (SetCursor(gNormalCursor HaveMouse()) = gCurrentCursor gNormalCursor)
                    
                 (if(PrintCantDoThat($400))
(send gInv:showSelf(gEgo))
(send pEvent:claimed(TRUE))
    )(else
    (send pEvent:claimed(TRUE))
)
)
(if((> (send pEvent:x) (ObjectButton:nsLeft))and
                     (< (send pEvent:x) (ObjectButton:nsRight))and
                     (> (send pEvent:y) (ObjectButton:nsTop))and
                     (< (send pEvent:y) (ObjectButton:nsBottom)))
                    
                    = selected TRUE
                    (SetCursor(gNormalCursor HaveMouse()) = gCurrentCursor gNormalCursor)
                    
                 (if(> gCurrentObject 0)
    SetCursor(gCurrentObject HaveMouse())
    (send pEvent:claimed(TRUE))
  )(else
  (send gInv:showSelf(gEgo))
  (send pEvent:claimed(TRUE))
)
)
(if((> (send pEvent:x) (SaveButton:nsLeft))and
                     (< (send pEvent:x) (SaveButton:nsRight))and
                     (> (send pEvent:y) (SaveButton:nsTop))and
                     (< (send pEvent:y) (SaveButton:nsBottom)))
                    
                    = selected TRUE
                    (SaveButton:cel(1))
                    (SetCursor(gNormalCursor HaveMouse()) = gCurrentCursor gNormalCursor)
                    
                 (send gGame:save())
                 (send pEvent:claimed(TRUE))
)
(if((> (send pEvent:x) (LoadButton:nsLeft))and
                     (< (send pEvent:x) (LoadButton:nsRight))and
                     (> (send pEvent:y) (LoadButton:nsTop))and
                     (< (send pEvent:y) (LoadButton:nsBottom)))
                    
                    = selected TRUE
                    (LoadButton:cel(1))
                    (SetCursor(gNormalCursor HaveMouse()) = gCurrentCursor gNormalCursor)
                    
                 (send gGame:restore())
                 (send pEvent:claimed(TRUE))
)
(if((> (send pEvent:x) (QuitButton:nsLeft))and
                     (< (send pEvent:x) (QuitButton:nsRight))and
                     (> (send pEvent:y) (QuitButton:nsTop))and
                     (< (send pEvent:y) (QuitButton:nsBottom)))
                    
                    = selected TRUE
                    (QuitButton:cel(1))
                    (SetCursor(gNormalCursor HaveMouse()) = gCurrentCursor gNormalCursor)
                    
                 (if(Print(
  "Do you really want to quit?"
  #title "Quit"
  #font gDefaultFont
  #button " Quit " 1
  #button " Oops " 0
)
  )
= gQuitGame TRUE
(send pEvent:claimed(TRUE))
)(else
(if(< gCurrentAction 5)
SetCursor(gCurrentAction HaveMouse())
)(else
(if(== gCurrentAction 5)
SetCursor(gCurrentObject)
)
)
(send pEvent:claimed(TRUE))
)

)
)
)
)
    (method (ShowIconbar)
     (if (not IconbarShowing)
     (WalkButton:show())
         (LookButton:show())
         (UseButton:show())
         (TalkButton:show())
         (InvButton:show())
         (if(> gCurrentObject 0)
  (ObjectButton:show()cel(1))
  )(else
         (ObjectButton:show()cel(0))
)
         (SaveButton:show())
         (LoadButton:show())
         (QuitButton:show())
         = IconbarShowing TRUE
)
)
(method (HideIconbar)
(if (IconbarShowing)
(WalkButton:hide()cel(0))
         (LookButton:hide()cel(0))
         (UseButton:hide()cel(0))
         (TalkButton:hide()cel(0))
         (InvButton:hide()cel(0))
         (ObjectButton:hide())
         (SaveButton:hide()cel(0))
         (LoadButton:hide()cel(0))
         (QuitButton:hide()cel(0))
         = IconbarShowing FALSE
)
)
)
/******************************************************************************/
(instance WalkButton of Prop
(properties
view 700
loop 0
cel 0
x 0
y 0
priority -1
)
)
(instance LookButton of Prop
(properties
view 700
loop 1
cel 0
x 36
y 0
priority -1
)
)
(instance UseButton of Prop
(properties
view 700
loop 2
cel 0
x 72
y 0
priority -1
)
)
(instance TalkButton of Prop
(properties
view 700
loop 3
cel 0
x 108
y 0
priority -1
)
)
(instance InvButton of Prop
(properties
view 700
loop 4
cel 0
x 144
y 0
priority -1
)
)
(instance ObjectButton of Prop
(properties
view 700
loop 5
cel 0
x 180
y 0
priority -1
)
)
(instance SaveButton of Prop
(properties
view 700
loop 6
cel 0
x 216
y 0
priority -1
)
)
(instance LoadButton of Prop
(properties
view 700
loop 7
cel 0
x 252
y 0
priority -1
)
)
(instance QuitButton of Prop
(properties
view 700
loop 8
cel 0
x 288
y 0
priority -1
)
)

Room 1 Script:
Code: [Select]
/******************************************************************************
 SCI Template Game
 By Brian Provinciano
 ******************************************************************************
 rm001.sc
 Contains the first room of your game.
 ******************************************************************************/
(include "sci.sh")
(include "game.sh")
/******************************************************************************/
(script 1)
/******************************************************************************/
(use "main")
(use "controls")
(use "cycle")
(use "game")
(use "feature")
(use "obj")
(use "inv")
(use "door")
(use "jump")
(use "dpath")
/******************************************************************************/
(instance public rm001 of Rm
(properties
picture scriptNumber
// Set up the rooms to go to/come from here
north 0
east 0
south 0
west 0
)
(method (init)
// same in every script, starts things up
   (super:init())
   (self:setScript(RoomScript)setRegions(CURSORMENU_RGN))
  
   // Check which room ego came from and position it
   (switch(gPreviousRoomNumber)
            /******************************************************
             * Put the cases here for the rooms ego can come from *
             ******************************************************/ /*
            (case North
   (send gEgo:
    posn(150 130)
    loop(1)
   )
   )*/
            // Set up ego's position if it hasn't come from any room
   (default
   (send gEgo:
   posn(150 130)
   loop(1)
   )
   )
   )

// Set up the ego
SetUpEgo()
(send gEgo:init())
(Guy:init())

        /****************************************
         * Set up the room's music to play here *
         ****************************************/ /*
(send gTheMusic:
prevSignal(0)
stop()
number(scriptNumber)
loop(-1)
play()
)*/

        /**************************************************
         * Add the rest of your initialization stuff here *
         **************************************************/
        
  )
)
/******************************************************************************/
(instance RoomScript of Script
(properties)
(method (handleEvent pEvent)
        (super:handleEvent(pEvent))

        /*****************************************
         * Handle the things here                *
         *****************************************/
      
        (if (not == (send pEvent:modifiers) emRIGHT_BUTTON)
         (switch( (gCurrentAction) )
          (case cmLOOK
          
           (if (> ( + 8 (send pEvent:x)) (Guy:nsLeft) and < ( + 8 (send pEvent:x)) (Guy:nsRight))
            (if (> ( + 8 (send pEvent:y)) (Guy:nsTop) and < ( + 8 (send pEvent:y)) (Guy:nsBottom))
             Print("It's a guy.")
             (send pEvent:claimed(TRUE))
)
  )
   
)
 (case cmUSE
 
  (if (> ( + 8 (send pEvent:x)) (Guy:nsLeft) and < ( + 8 (send pEvent:x)) (Guy:nsRight))
            (if (> ( + 8 (send pEvent:y)) (Guy:nsTop) and < ( + 8 (send pEvent:y)) (Guy:nsBottom))
             Print("There is nothing to use at.")
   )
  )
 
     )
          (case cmTALK
          
           (if (> ( + 2 (send pEvent:x)) (Guy:nsLeft) and < ( + 2 (send pEvent:x)) (Guy:nsRight))
            (if (> (+ 14 (send pEvent:y)) (Guy:nsTop) and < (+ 14 (send pEvent:y)) (Guy:nsBottom))
             Print("There is nothing to talk at.")
   )
  )
 )
    ) //end switch
   ) //end if

        /*****************************************
         * Handle the possible said phrases here *
         *****************************************/      
        (if (== gPreviousRoomNumber 976)
         SetCursor(001 HaveMouse())
         = gPreviousRoomNumber 0
)
  )
)
/******************************************************************************/
(instance Guy of Prop
(properties
view 0
x 40
y 100
)
)

Section of code from User.sc pertinent to PNC interface:
Code: [Select]
// Global commands
(method (handleEvent pEvent)
(var direction)
(if( not (super:handleEvent(pEvent)) )
   (switch( (send pEvent:type) )
(case evMOUSEBUTTON
(if(not (& (send pEvent:modifiers) emRIGHT_BUTTON))
                  (switch( (gCurrentAction) )
                   (case 1
                   (if (User:controls)  
(self:
 setMotion(
  MoveTo
  (+ 8 (send pEvent:x))
  (+ 15 (send pEvent:y))
 )
)
)
  ) //end case 1
  (case 2
    (if((> (+ 8 (send pEvent:x)) (send gEgo:nsLeft))and
                        (< (+ 8 (send pEvent:x)) (send gEgo:nsRight))and
                        (> (+ 8 (send pEvent:y)) (send gEgo:nsTop))and
                        (< (+ 8 (send pEvent:y)) (send gEgo:nsBottom)))
                     Print("That's you, the star of this fine game!")
)
  ) //end case 2
  (case 3
    (if((> (+ 8 (send pEvent:x)) (send gEgo:nsLeft))and
                        (< (+ 8 (send pEvent:x)) (send gEgo:nsRight))and
                        (> (+ 8 (send pEvent:y)) (send gEgo:nsTop))and
                        (< (+ 8 (send pEvent:y)) (send gEgo:nsBottom)))
                     Print("Ew.")
)
  ) //end case 3
  (case 4
   (if((> (+ 2 (send pEvent:x)) (send gEgo:nsLeft))and
                        (< (+ 2 (send pEvent:x)) (send gEgo:nsRight))and
                        (> (+ 14 (send pEvent:y)) (send gEgo:nsTop))and
                        (< (+ 14 (send pEvent:y)) (send gEgo:nsBottom)))
                     Print("Talking to yourself again?")
)
  ) //end case 4
  (case 5
  (switch( (gCurrentObject) )
  (case 801
     (if((> (send pEvent:x) (send gEgo:nsLeft))and
                          (< (send pEvent:x) (send gEgo:nsRight))and
                          (> (send pEvent:y) (send gEgo:nsTop))and
                          (< (send pEvent:y) (send gEgo:nsBottom)))
                       Print("O NOES!" #font LARGE_FONT)
                       ShakeScreen(10 ssLEFTRIGHT)
                       ShakeScreen(10 ssUPDOWN)
                       Print("Didn't your mom tell you to NEVER use a question mark on yourself!")
 )
)
)
  ) //end case 5
 ) //end switch
) //end if
        
                 (if(& (send pEvent:modifiers) emRIGHT_BUTTON)
                  (switch( (gCurrentAction) )
                   (case 1
                   (= gCurrentAction 2)
                   SetCursor(002 HaveMouse())
  )
  (case 2
  (= gCurrentAction 3)
  SetCursor(003 HaveMouse())
  )
  (case 3
  (= gCurrentAction 4)
  SetCursor(004 HaveMouse())
  )
  (case 4
  (if (> gCurrentObject 0)
  (= gCurrentAction 5)
  SetCursor(gCurrentObject HaveMouse())
)(else
    = gCurrentAction 1
    SetCursor(001 HaveMouse())
   )
  )
  (case 5
  (= gCurrentAction 1)
  SetCursor(001 HaveMouse())
  ) // end case
 ) //end switch
) //end if

// Make sure it's the left button
//(if(not (& (send pEvent:modifiers) emRIGHT_BUTTON)
//    and (User:controls) )  
// (self:
// setMotion(
// MoveTo
// (send pEvent:x)
// (send pEvent:y)
// )
// )
// (User:prevDir(CENTER))
// (send pEvent:claimed(TRUE))
// )
)
   (case evJOYSTICK
   = direction (send pEvent:message)
   (if( (== direction (User:prevDir)) and (IsObject(mover)))
    = direction CENTER
    )
    (User:prevDir(direction))
    (self:setDirection(direction))
    (send pEvent:claimed(TRUE))
   )
   )
   )
   return(send pEvent:claimed)
)

The code from User.sc works and doesn't repeat when clicking away from the message. But the code in the room script does.
« Last Edit: February 11, 2012, 12:49:36 PM by MusicallyInspired »
Brass Lantern Prop Competition

Offline gumby

Re: Point & Click (click events)
« Reply #10 on: February 11, 2012, 04:03:46 PM »
Shouldn't you have the (send pEvent:claimed(TRUE)) at the end of each case like you did with the first code section (below)?

Code: [Select]
             Print("It's a guy.")
             (send pEvent:claimed(TRUE))


Code: [Select]
             Print("There is nothing to use at.")
             <HERE>

Code: [Select]
             Print("There is nothing to talk at.")
             <HERE>

May not fix your problem, but it would be consistent.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline MusicallyInspired

Re: Point & Click (click events)
« Reply #11 on: February 12, 2012, 12:45:34 AM »
Ah, I thought I had. Anyway, it probably won't make the difference. And I don't know WHY. Something else is wrong somewhere. I just can't see it, though.
Brass Lantern Prop Competition

Offline Cloudee1

Re: Point & Click (click events)
« Reply #12 on: February 12, 2012, 08:44:24 PM »
I downloaded the template, when i get a chance I will see what i can do about recreating the trouble.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.034 seconds with 16 queries.