Author Topic: Scaling, swimming, or just all around changing ego's view based off of controls  (Read 4118 times)

0 Members and 1 Guest are viewing this topic.

Offline Cloudee1

Whether you want your ego to scale, or change views when walking in water, the basic concept is pretty simple. Drop some control color blocks and in your RoomScript Doit method you will want to check what control color your ego is on, and adjust the view accordingly.

The basic idea:
Code: [Select]
(instance RoomScript of Script
(properties)
  (method (doit)
  (super:doit())

//**********************************************
// Control Ego View based off of the control color ego is on
//**********************************************

  (if (== (send gEgo:onControl()) ctlGREEN)(send gEgo:view(1)))
  (else
      (if (== (send gEgo:onControl()) ctlTEAL)(send gEgo:view(2)))
      (else
  (if (== (send gEgo:onControl()) ctlNAVY)(send gEgo:view(3)))
          (else
      (if (== (send gEgo:onControl()) ctlBLACK)(send gEgo:view(0)))
          )
       )
   )

    //**********************
    // insert other doit code here
    //**********************

  ) // end doit method

That is basicly the heart of the matter. However, there is a couple of things we should do to help out our code a little bit. The doit method checks every cycle. Let's take for instance your ego is standing on the Navy control color. Every cycle, the game is going to set the ego view to 3, set the ego view to 3, set the ego view to 3, over and over and over again. While visually this won't be a problem, it does bog your game down a bit and could lead to some memory issues. Beside the fact that really we only need to change the ego view to 3 if the ego is on Navy and isn't currently set to 3. Easy enough to fix, we just need to add in another check. This time looking at both the control color ego is standing on as well as the current view.

Code: [Select]
(instance RoomScript of Script
(properties)
  (method (doit)
  (super:doit())

//**********************************************
// Control Ego View based off of the control color ego is on
//**********************************************

  (if ((== (send gEgo:onControl()) ctlGREEN) and (not(== (send gEgo:view) 1)))
  (send gEgo:view(1))
  )
  (else
      (if ((== (send gEgo:onControl()) ctlTEAL) and (not(== (send gEgo:view) 2)))
      (send gEgo:view(2))
      )
      (else
  (if ((== (send gEgo:onControl()) ctlNAVY) and (not(== (send gEgo:view) 3)))
          (send gEgo:view(3))
          )
          (else
      (if ((== (send gEgo:onControl()) ctlBLACK) and (not(== (send gEgo:view) 0)))
              (send gEgo:view(0))
              )
          )
       )
   )

    //**********************
    // insert other doit code here
    //**********************

  ) // end doit method

We are definately getting closer. Now there may be times, that for whatever reason, you don't want the ego to scale. Whether because of a cutscene or some other business that you may need to take control of the ego's view regardless of the control colors. The Doit method is immediately going to try and take control back. We really should build in some sort of variable which allows us to take control when we want to. Simple enough, create a local variable named whatever you want, but it would usually help if it describes what it is that it does. So to that end, I'll call it doScale. So up at the top of your script, just after the uses, add in the local variable.

Code: [Select]
/******************************************************************************
// rm002.sc                                                             
//******************************************************************************
(include "sci.sh")(include "game.sh")                                 (script 2)
//*****************************************************************************
(use "main")(use "controls")(use "cycle")(use "game")(use "feature")(use "obj")
//*****************************************************************************
(local
 doScale = TRUE
)

Now we wrap our last bit of code for the scaling around a check of this new variable. If it is true, then ego will scale. If it isn't, ego will stop changing when going onto a new control area.

Code: [Select]
(instance RoomScript of Script
(properties)
  (method (doit)
  (super:doit())

//**********************************************
// Control Ego View based off of the control color ego is on
//**********************************************

(if(doScale)
  (if ((== (send gEgo:onControl()) ctlGREEN) and (not(== (send gEgo:view) 1)))
  (send gEgo:view(1))
  )
  (else
      (if ((== (send gEgo:onControl()) ctlTEAL) and (not(== (send gEgo:view) 2)))
      (send gEgo:view(2))
      )
      (else
  (if ((== (send gEgo:onControl()) ctlNAVY) and and (not(== (send gEgo:view) 3)))
          (send gEgo:view(3))
          )
          (else
      (if ((== (send gEgo:onControl()) ctlBLACK) and and (not(== (send gEgo:view) 0)))
              (send gEgo:view(0))
              )
          )
       )
   )
) // ends if doScale is true

    //**********************
    // insert other doit code here
    //**********************

  ) // end doit method

And there you go. Now all you need is a room with the control areas defined and you should be good to go.
« Last Edit: September 12, 2014, 07:34:51 AM by Cloudee1 »


Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Collector

Nice to see an example of this.
KQII Remake Pic

Offline MusicallyInspired

I kept forgetting to write one of these as I had used it in KQ2SCI. Nice to see it on here and probably well more documented than I could ever write!
Brass Lantern Prop Competition


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

Page created in 0.034 seconds with 24 queries.