Author Topic: how do you use distanceTo or inRect with actors instead of the ego?  (Read 5854 times)

0 Members and 1 Guest are viewing this topic.

Offline stateofpsychosis

I'm trying to make it so the actors also trigger the bomb in my script
but I can only get it working for the ego


obviously I can't send to aMan

here's the snippet of code i'm working on (not the whole thing since we've already been over the rest of it)

Code: [Select]
(if(bombAble) // the timer on bomb has been reached ... it will do what follows
      = bombAble FALSE // we only want to do it once, so turn this trigger variable back off
       
      (if(aMan:inRect((- inventory2X 30) (- inventory2Y 30) (+ inventory2X  30) (+ inventory2Y 30)))
       
     
        (aMan:view(37)setCycle(End)cel(0)loop(0)) // again not sure what this view is doing, guessing bomb blowing up!!
   
        (aMan:setMotion(NULL))
       
  )
      (else
          // ego more than 50 away... do nothing
  )
   = inventory2Room 0// reset the global variable
   = inventory2Y 0 // reset the global variable
   = inventory2Y 0 // reset the global variable
   (inventory2View:posn(400 400)hide()) // get the item view off screen
)

so yea removing the (send made it not work at all

no need to write the code for me here

I just simply need to know how to use these things on actors cause I'm missing something
thanks!



Offline Cloudee1

Re: how do you use distanceTo or inRect with actors instead of the ego?
« Reply #1 on: November 21, 2014, 11:20:03 AM »
I would think that would work... just to clarify though, the actor isn't triggering the bomb as it is written but rather blows up when the bomb blows up if they are in the rectangle at that moment

There is always the long way of coding out the rectangle in case inRect isn't usable on an actor besides the ego which off hand I don't know if they are...

if a man x is greater than bomb area x and
 if a man x is less than bomb area x and
  if a man y is greater than bomb area y and
   if a man y is less than bomb area
   blow up man
« Last Edit: November 21, 2014, 11:22:19 AM by Cloudee1 »
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline stateofpsychosis

Re: how do you use distanceTo or inRect with actors instead of the ego?
« Reply #2 on: November 21, 2014, 02:29:40 PM »
hmmm.. yes i'll try that ... you're right i can't see why this isn't working the way I tried it

perhaps i made some other mistake..

I'll keep digging

Offline stateofpsychosis

Re: how do you use distanceTo or inRect with actors instead of the ego?
« Reply #3 on: December 04, 2014, 03:28:46 PM »
I finally had time to take another stab at it and figured out

I think the cause was some ambiguity in the code which is always a no no.

so these are the fixed instances just in case anyone ever wants to try the same thing:

Code: [Select]
(instance boom2Script of Script
(properties)
  (method (changeState newState)
  = state newState
    (switch (newState)
      (case 0
      (inventory2View:view(39)setCycle(Fwd) loop(0)) //fuse burning view
       = seconds 6)// how long before bomb is ready to explode
      (case 1 (inventory2View:view(34)setCycle(Fwd) loop(0)) // explosion view
               = cycles 5 )
      (case 2 = bombAble TRUE)// Tells our doit method to trigger...
       
    ) // end switch
  )// end method
  //**************************************
  (method (doit)  // using a doit method to explode the bomb...
  (var dyingScript)
  (super:doit())
    (if(bombAble) // the timer on bomb has been reached ... it will do what follows
    = bombAble FALSE // we only want to do it once, so turn this trigger variable back off
   
   
    (if(aMan:inRect((- inventory2X 30) (- inventory2Y 30) (+ inventory2X  30) (+ inventory2Y 30)))
       
        (aMan:setMotion(NULL))
       
    (aMan:view(40)setCycle(End)cel(0)loop(4)) // robot blowing up
   
      )// ends robot exploded....
     
     
      (if(send gEgo:inRect((- inventory2X 30) (- inventory2Y 30) (+ inventory2X  30) (+ inventory2Y 30)))
        ProgramControl()
        (send gEgo:setMotion(NULL))
        // This should stop the ego if they are walking... if not you know what to do
       
    (send gEgo:view(37)setCycle(End)cel(0)loop(0)) // ego blowing up

    = dyingScript ScriptID(DYING_SCRIPT)
         (send dyingScript:
         caller(36)
         register("You blew yourself up. Good job. Way to die!")
         )
        (send gGame:setScript(dyingScript))
      )// ends ego exploded....
      (else
          // ego more than 50 away... do nothing
  )
  (send gEgo:setScript(hideScript))


 )))



(instance hideScript of Script
(properties)
 
  (method (doit)  // using a doit method to hide the bomb...

  (super:doit())

   = inventory2Room 0// reset the global variable
   = inventory2Y 0 // reset the global variable
   = inventory2Y 0 // reset the global variable
   (inventory2View:posn(400 400)hide()) // get the item view off screen
))


what seemed to fix it was separating the resetting of the global variables and the hiding of the view from it and calling a new script for that.  I think that's what it was anyways :P



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

Page created in 0.036 seconds with 22 queries.