Community

SCI Programming => SCI Syntax Help => Topic started by: jtyler125 on January 13, 2007, 12:05:58 PM

Title: Adding a clock?? And Appearing objects
Post by: jtyler125 on January 13, 2007, 12:05:58 PM
I am pretty sure Brian talks about adding a clock...if not any suggestions of how to do it and does anyone know how to make it restart count down when you pick up an object?

1)  How to add a clock and restart it after doing somethig?

2)  How do you make new objects appear after you pick up and object on the screen?

You guys have totally rejuvenated my interest in Sci Studio.

Thanks,
JT
Title: Re: Adding a clock?? And Appearing objects
Post by: Cloudee1 on January 13, 2007, 03:13:47 PM
So here's the inside story on timers. Supposedly there is a whole timer class I believe but so far no one has ever realy announced that they figured out how to use it for anything.

Using a doit method however  it does become possible to count cycles so it turns out we really don't need timers necesarily.

heres the jist. If you want a clock that counts while you travel through multiple rooms then you will need to make global variables. In the main script, at the top where all of the other variable = somethings are listed add in however many countdown variables you need. It is very important to compile all scripts after making any main script edits!! This is a close approximation to my round timer for boxing in fabulous las vegas.

Code: [Select]

countdownminutes = 10 // the count
countdownseconds = 59 // the count
milsec = 5 // cycles per second
countmilsec = 5 // the count


If you only need this in a single room, and the ego can't leave the room then you could place these in a (local ... ) declaration underneath the uses stuff at the top, if the ego leaves and comes back the timer is reset to it's original value this way, using global variables then they will not forget what numbers they were on.

Now in order to see the countdown, you are going to need to display these values of numbers to the screen. the countmilsec variable is used to count the actual cycles so we won't display that. Since this is my own script and there were several different times to write the same bit of info to the screen, I made these statements into  procedures. To use these, you will simply need to place this whole bit below everything else, outside of all of the instances.

Code: [Select]

(procedure public (Writemin)                                  // display Minutes
(var textstring[50])
    Format(@textstring "%2d" countdownminutes)
    Display(@textstring dsCOORD  144 8  dsCOLOR 00 dsFONT 4 dsBACKGROUND 15 dsWIDTH 10)
)

(procedure public (Writesec)                                  // display Seconds
(var textstring[50])
    (if(< countdownseconds 0)   = countdownseconds 0) // resets seconds if it dips negative

    Format(@textstring "%2d" countdownseconds)
    Display(@textstring dsCOORD 156 8 dsCOLOR 00 dsFONT 4 dsBACKGROUND 15 dsWIDTH 12)
)


Now whenever we need to update the times displayed it can be done by simply using  Writemin() and Writesec().  Now would be a good time to add those into the rooms init instance where all of your rooms views and actors are inited, so the screen will start off with all of the necesary values displayed.

Code: [Select]

 Writemin()                     // update minutes displayed
 Writesec()


So I suppose now it is time make the part that does the counting.

Code: [Select]

  (method (doit)
  (super:doit())

    (if(== countmilsec 0)
      (if(== countdownseconds 0)
        (if(== countdownminutes 0)  // all three timers reach 0

           //  ... countdown at 0, now what


        )
        (else   // milsec and sec at 0 but not min
        = countdownminutes --countdownminutes  // so subtract one minute
        = countdownseconds 59  // changes the 0 to 60 to keep timer counting down
        Writemin()  // update minutes displayed
        Writesec()
        = countmilsec milsec // resets milsec to cycle delay
        )
      )
      (else  // milisec at 0 but not seconds
      = countdownseconds --countdownseconds  // so subtract one second
      Writesec()  // update seconds displayed
      = countmilsec milsec     // resets milsec to cycle delay
      )
    )


    = countmilsec --countmilsec  // subtract one from milisec each cycle

) // end method

And there you have a clock timer. It's not perfect in that seconds aren't always displayed as two digits. 00 - 09 are displayed as 0-9. But it counts down. Whenever you want to add more time, all you have to do is something like "= countdownminutes (+ countdownminutes 7)" or you could reset it regardless of what value it is on by doing "= countdownminutes 2"

As for number 2, you can simply add in the views init statement in the same place you told ego to get the first item. It would need an instance just like everything else. But other than that you are just moving it from the init method to the handle event method since it is being triggered by a user input instead of automatically inited.

Code: [Select]

(if(Said('get'/'rock'))
  Print("ok")
  Print("Hey, there's a strange plant under the rock")
  (send gEgo:get(INV_ROCK))
  (rock:hide())
  (plant:setPri(13)ignoreActors()init())
  // = countdownminutes (+ countdownminutes 7)
) // end said rock



the rock would disappear and the plant appear.
Title: Re: Adding a clock?? And Appearing objects
Post by: jtyler125 on January 13, 2007, 11:13:57 PM
Cloudee1,

You are kind for a week, give yourself a crown...damn...the clock is on the screen, but it won't start counting down what did I do wrong.  By the way I can't beleive that I could just plop that stuff into the script and it actually compiled...I was amazed.

Now...the clock is for one room...like you mentioned, and when/if it gets to zero the game is over...any suggestions?
Title: Re: Adding a clock?? And Appearing objects
Post by: Cloudee1 on January 13, 2007, 11:24:41 PM
I don't know exactly I would have to see your code. If it isn't counting down it is probably because of one of two reasons that I could guess about.

1. something is wrong with your doit method, probably closing before the --milsec part at the bottom. Nothing changes till it reaches 0 th first time, so it might not be making it to 0
2. something is wrong with the display, so it is counting down, but it isn't writing it to the screen. Are you sure the procedures to write it are clear at the bottom, after every possible thing, not a single ) should come after them.

Thats my guesses anyway. Feel free to stick it up here, let's see what you did.
Title: Re: Adding a clock?? And Appearing objects
Post by: jtyler125 on January 13, 2007, 11:38:58 PM
Here is my yucky newbie script sorry if messy I write notes to myself in the margins and all...

/******************************************************************************
 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")
(use "wander")
(use "follow")
 /*so the ghost moves*/
 
(local countdownminutes = 0 // the count
countdownseconds = 59 // the count
milsec = 5 // cycles per second
countmilsec = 5) // the count
 
/******************************************************************************/
(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))
        
        // 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(210 110)
                 loop(2)
              )
           )*/
            // 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())

  Writemin()                     // update minutes displayed
 Writesec()

(aMan:
ignoreControl(ctlWHITE)
init()
setCycle(Walk)
setMotion(Follow gEgo)
setMotion(Wander)
)
/*(aMan:
  ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
) */
(aMan2:
  ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(aMan3:
  ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(aMan4:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape1:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape2:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
 (Grape3:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape4:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape5:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape6:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape7:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape8:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape9:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape10:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape11:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
(Grape12:
 ignoreControl(ctlWHITE)
  init()
  setMotion(Wander)
)
  /****************************************
         * 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 (doit)
 (var dyingScript)
 (super:doit())

 (if(not(gProgramControl))             //Death-handler script provided by Cloudee1
    (if(< (send gEgo:distanceTo(aMan)) 15)
       ProgramControl()
       = dyingScript ScriptID(DYING_SCRIPT)
       (send dyingScript:caller(3)register("Pinky Pink got you... for directions start a new game and type look."))
       (send gGame:setScript(dyingScript))
    )

    (if(< (send gEgo:distanceTo(aMan2)) 15)
       ProgramControl()
       = dyingScript ScriptID(DYING_SCRIPT)
       (send dyingScript: caller(4)register("Redman got you... "))
       (send gGame:setScript(dyingScript))
    )

    (if(< (send gEgo:distanceTo(aMan3)) 15)
       ProgramControl()
       = dyingScript ScriptID(DYING_SCRIPT)
       (send dyingScript:caller(5)register("Greenie got you... for directions start a new game and type look."))
       (send gGame:setScript(dyingScript))
    )

   (if(< (send gEgo:distanceTo(aMan4)) 15)
       ProgramControl()
       = dyingScript ScriptID(DYING_SCRIPT)
       (send dyingScript:caller(6)
       register("Purple Nurple got you... for directions start a new game and type look."))
       (send gGame:setScript(dyingScript))
    )
  ) // ends not program control
 )// end method

 (method (handleEvent pEvent)
 (super:handleEvent(pEvent))

 (if(Said('look>'))
                             (if(Said('/room,(a)'))
                             Print("There are grapes and ghosts everywhere.")
                    )(else
                              (if(Said('/(ghost)'))
                             Print("They look scary, better to stay away from them.")
                    )(else
                            (if(Said('/(grape)'))
                             Print("They look good enough to eat.")
                    )(else
                             (if(Said('[ /* , !* ]')
                             Print("There are grapes with numbers in this room... To eat them type `eat grape1' or `eat grape2' etc... According to a tradition in Spain, eat 12 grapes before the New Year and you will have good luck for the whole year.")

)
)
)
)
)


/*the brackets above close the special look different things option*/
                           )(else
                            (if(Said('eat>'))
                            (if(Said('/grape1'))
                            (if(send gEgo:has(INV_GRAPE1))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape1)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE1))
                            (Grape1:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape2'))
                            (if(send gEgo:has(INV_GRAPE2))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape2)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE2))
                            (Grape2:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape3'))
                            (if(send gEgo:has(INV_GRAPE3))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape3)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE3))
                            (Grape3:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape4'))
                            (if(send gEgo:has(INV_GRAPE4))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape4)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE4))
                            (Grape4:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape5'))
                            (if(send gEgo:has(INV_GRAPE5))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape5)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE5))
                            (Grape5:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape6'))
                            (if(send gEgo:has(INV_GRAPE6))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape6)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE6))
                            (Grape6:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape7'))
                            (if(send gEgo:has(INV_GRAPE7))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape7)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE7))
                            (Grape7:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape8'))
                            (if(send gEgo:has(INV_GRAPE8))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape8)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE8))
                            (Grape8:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape9'))
                            (if(send gEgo:has(INV_GRAPE9))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape9)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE9))
                            (Grape9:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape10'))
                            (if(send gEgo:has(INV_GRAPE10))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape10)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE10))
                            (Grape10:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
                      )(else
                            (if(Said('eat>'))
                            (if(Said('/grape11'))
                            (if(send gEgo:has(INV_GRAPE11))
                           Print("You already have it!")
                          )(else
                            (if(< (send gEgo:distanceTo(Grape11)) 15)
                           Print("O.K.")
                            (send gEgo:get(INV_GRAPE11))
                            (Grape11:hide())
                            (send gGame:changeScore(1))
                          )(else
                           Print("You're not close enough!")
                     )
                     )
         /*If said take one object above - take the second object below*/
                  )(else
                   (if(Said('eat>'))
                   (if(Said('/grape12'))
                   (if(send gEgo:has(INV_GRAPE12))
                   Print("You already have it!")
                   )(else
                   (if(< (send gEgo:distanceTo(Grape12)) 15)
                   Print("O.K.")
                   (send gEgo:get(INV_GRAPE12))
                   (Grape12:hide())
                   (send gGame:changeScore(1))
                   )(else
                   Print("You're not close enough!")

         )
)
)
)

)
)
)
)
))))))))))))))))))))
(method (doit)
  (super:doit())

    (if(== countmilsec 0)
      (if(== countdownseconds 0)
        (if(== countdownminutes 0)  // all three timers reach 0

           //  ... countdown at 0, now what


        )
        (else   // milsec and sec at 0 but not min
        = countdownminutes --countdownminutes  // so subtract one minute
        = countdownseconds 59  // changes the 0 to 60 to keep timer counting down
        Writemin()  // update minutes displayed
        Writesec()
        = countmilsec milsec // resets milsec to cycle delay
        )
      )
      (else  // milisec at 0 but not seconds
      = countdownseconds --countdownseconds  // so subtract one second
      Writesec()  // update seconds displayed
      = countmilsec milsec     // resets milsec to cycle delay
      )
    )


    = countmilsec --countmilsec  // subtract one from milisec each cycle

) // end method



/* the bracket below this line closes the Room Instance Script*/
)


  /* (if(Said('look'))
    Print("You are in a room...ahhhh there are ghosts all around you stay away from them!!!  But hey, there is also a grape wandering around... According to a tradition in Spain, eat 12 grapes before the New Year and you will have good luck for the whole year.")
   )// end said look

 ) // end method
) // end roomscript instance*/

(instance aMan of Act  (properties y 185 x 220  view 3))
(instance aMan2 of Act  (properties y 18 x 20    view 4))
(instance aMan3 of Act (properties y 85 x 200 view 5))
(instance aMan4 of Act (properties y 50 x 10 view 6))
(instance Grape1 of Act (properties y 100 x 100 view 7))
(instance Grape2 of Act (properties y 100 x 100 view 8))
(instance Grape3 of Act (properties y 100 x 100 view 9))
(instance Grape4 of Act (properties y 185 x 220 view 10))
(instance Grape5 of Act (properties y 185 x 220 view 11))
(instance Grape6 of Act (properties y 185 x 220 view 12))
(instance Grape7 of Act (properties y 50 x 10 view 13))
(instance Grape8 of Act (properties y 50 x 10 view 14))
(instance Grape9 of Act (properties y 50 x 10 view 15))
(instance Grape10 of Act (properties y 185 x 220 view 16))
(instance Grape11 of Act (properties y 185 x 220 view 17))
(instance Grape12 of Act (properties y 18 x 20 view 18))

(procedure public (Writemin)                                  // display Minutes
   (var textstring[50])
    Format(@textstring "%2d" countdownminutes)
    Display(@textstring dsCOORD  144 8  dsCOLOR 00 dsFONT 4 dsBACKGROUND 15 dsWIDTH 10)
)

(procedure public (Writesec)                                  // display Seconds
   (var textstring[50])
    (if(< countdownseconds 0)   = countdownseconds 0) // resets seconds if it dips negative

    Format(@textstring "%2d" countdownseconds)
    Display(@textstring dsCOORD 156 8 dsCOLOR 00 dsFONT 4 dsBACKGROUND 15 dsWIDTH 12)
)
Title: Re: Adding a clock?? And Appearing objects
Post by: Cloudee1 on January 14, 2007, 12:02:17 AM
Ok I looked it over and the first issue I see is that there are two seperate doit methods. One of the two's contents need to join the other one. Just cut and paste what's inside the second one to just before the first doit method closes.

Another thing I noticed is where you init aman
(aMan:
...
setMotion(Follow gEgo)
setMotion(Wander)
)
you can't really have him wander and follow at the same time.
Title: Re: Adding a clock?? And Appearing objects
Post by: jtyler125 on January 14, 2007, 12:08:01 AM
I know he can't wander and follow at the same time...I just thought I try it to see what happens and yup...he just wanders.
Title: Re: Adding a clock?? And Appearing objects
Post by: Cloudee1 on January 14, 2007, 05:21:10 AM
Since your so close to finishing your entry, and you've still got a couple of weeks left, why not try to get the avoid script working that Troflip told us about. I think you can find it on his tutorials page, or definately somewhere in the posts at mega-tokyo. As soon as he signs up here I hope that is one that he posts to the template updates board. But a couple of avoids instead of all of those wanders might be a nice changeup.

I assume getting rid of the second doit method fixed the timer?
Title: Re: Adding a clock?? And Appearing objects
Post by: jtyler125 on January 14, 2007, 08:46:16 AM
Uh...oh, homework...clock works great....I will try to add the avoid script.

Thanks,
JT
Title: Re: Adding a clock?? And Appearing objects
Post by: jtyler125 on January 14, 2007, 09:44:18 PM
I can't find the avoid on MT...the only avoid I found was a message from you about the jump script...wen't there and it was interesting but not an avoid script.  I will look thorugh his posts next.