SCI Programming.com
Welcome, Guest. Please login or register.
June 29, 2017, 06:38:17 AM
Home  >  Tutorials  >  Chapter 13: Examples of Scripting Point and Click Responses
Chapter 13: Examples of Scripting Point and Click Responses

Now that we have our point and click game complete, it is time to run through a few examples of how to judge where it is that has been clicked and to handle the responses accordingly. Hopefully, you have actually looked through the code of clicking on our various menu buttons and items. If you have then this most of this should look very familiar. For the most part, every single one of them follows the same general patterm: check where clicked, check cursor, do response

Clicks on Views: Hopefully this looks very familiar. This is an example of scripting a click on a view. In this situation, there are two plant views and clicking on either will give the same response so we can code them together by throwing in an or.

Code:
// Click on View called plant1 or plant2 
(if(((> (send pEvent:x) (plant1:nsLeft))and
    (< (send pEvent:x) (plant1:nsRight))and
    (> (send pEvent:y) (plant1:nsTop))and
    (< (send pEvent:y) (plant1:nsBottom))) or
    ((> (send pEvent:x) (plant2:nsLeft))and
    (< (send pEvent:x) (plant2:nsRight))and
    (> (send pEvent:y) (plant2:nsTop))and
    (< (send pEvent:y) (plant2:nsBottom))))
     (switch(gCurrentCursor)
      (case 999 (send pEvent:type(evMOUSEBUTTON) claimed(FALSE))) // walk
      (case 998 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(1 10))// look
      (case 996 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(1 11))// talk
      (case 995 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(1 12))//  get
      (default  (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))// item
                (switch(Random(0 2))
                    (case 0 Print(950 22))
                    (case 1 Print(950 23))
                    (case 2 Print(950 24))
                )// end random switch
      )// end default/item case
     )// end current cursor switch
)// end if item

Clicks on Priority Colors: Let's say there are a couple of trees, or in this situation, pillars that are drawn into the picture resource. We can simply check if the click was on a specific priority color. Again, I have thrown in an or statement to cover two seperate pillars.

Code:
// Click on Priority Color grey or navy
(if((== $0100 OnControl(ocPRIORITY (send pEvent:x) (send pEvent:y)))   or    // GREY Priority Color
    (== $0002 OnControl(ocPRIORITY (send pEvent:x) (send pEvent:y))))        // NAVY Priority Color
     (switch(gCurrentCursor)
      (case 999 (send pEvent:type(evMOUSEBUTTON) claimed(FALSE))) // walk
      (case 998 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(3 43))// look
      (case 996 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(3 44))// talk
      (case 995 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(3 45))//  get
      (default  (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))// item
                (switch(Random(0 2))
                    (case 0 Print(950 22))
                    (case 1 Print(950 23))
                    (case 2 Print(950 24))
                )// end random switch
      )// end default/item case
     )// end current cursor switch
)// end if Priority

Clicks on Coordinates: Now I will show an example of clicks inside a coordinate box. Let's say that you have a sun drawn on your picture resource.

Code:
// Click on coordinate box
(if((> (send pEvent:x) 273) and
    (< (send pEvent:x) 320) and
    (> (send pEvent:y) 0) and
    (< (send pEvent:y) 45))
     (switch(gCurrentCursor)
      (case 999 (send pEvent:type(evMOUSEBUTTON) claimed(FALSE))) // walk
      (case 998 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(1 21))// look
      (case 996 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(1 22))// talk
      (case 995 (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(1 23))//  get
      (default  (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))Print(1 45))// item
     )// end current cursor switch
)// end if in box

A couple of things to note when it comes to the point and click scripting. It is very important that you place the click on segments in order of priority and that you make use of else statements. For example, Say you have a view walking in front of the pillar that includes a coordinate box and someone clicks on it. The chances are good that if you don't use else statements, all three responses will be returned. One for clicking on the view, one for clicking on the priority color, and one for clicking in the box. To prevent that from happening use else statements.

example:

(if click on view)
  (else
  (if click on priority)
    (else
    (if click inside box)
    )
  )
Now this is where the order of priority comes in. If clicks on the views are more important than the clicks on the priority color then it should come before it in the above example tree. The game will only check the next else statement if the one above it is false, and likewise, the script 950 responses will only be accessed if all of the room scripts statements are false. But hopefully you already know a little bit about that, if not, might I suggest you go through a few of the other tutorials.
There it is, a few examples to get you on your way!
<< Prev Back to Tutorials        

The SCI Programming Community
Copyright © 2007 - 2017, All Rights Reserved.