Author Topic: running into a running problem (bad joke lol)  (Read 2199 times)

0 Members and 1 Guest are viewing this topic.

Offline Doan Sephim

running into a running problem (bad joke lol)
« on: June 19, 2012, 12:46:49 PM »
So, my ego can run like the hero in Quest for Glory, but here is where things get tricky.

When you change the xStep and yStep while ego is already in the motion, he will continue walking at the original xandyStep until he is given a new destination. No problem! All I need to do is stop ego's movement, change his xandyStep and then direct him to his original destination. And that works perfectly but for one thing.

There are two different ways ego can be directed, and I don't have the knowledge to know how to tell the script to do one action for one and the other.

If clicked, this code works
Code: [Select]
(send gEgo:setMotion(MoveTo (send pEvent:x)(send pEvent:y)))
and if direction pad is used, this code works
Code: [Select]
(switch (send gEgo:loop)
                    (case 0
                        (send gEgo:setDirection(RIGHT))
                    )(case 1
                        (send gEgo:setDirection(LEFT))
                    )(case 2
                        (send gEgo:setDirection(DOWN))
                    )(case 3
                        (send gEgo:setDirection(UP))
                    )
)

I just don't know how exactly to code the if statement. Any thoughts?


Artificial Intelligence Competition

Offline Cloudee1

Re: running into a running problem (bad joke lol)
« Reply #1 on: June 22, 2012, 12:11:46 PM »
I would think that for now at least you could simply slap the bit about the mouse into the handleEvent method and run with it. The pnc tutorial has some sample code for checking for mouse clicks. Then maybe stick the arrow key stuff in a Doit method
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Doan Sephim

Re: running into a running problem (bad joke lol)
« Reply #2 on: June 22, 2012, 12:18:17 PM »
The thing about checking for mouse clicks is something I did try. I think it worked for when you had clicked to walk somewhere, but when you hadn't it sent you in a wierd direction.

So then I tried setting up a switch in case of mousepress and in case of direction pad, but I couldn't get the code to work.

And the key is, all this is in response to the player typing "run"...and I should mention its in the main script, if that is going to matter at all.
« Last Edit: June 22, 2012, 12:23:07 PM by Doan Sephim »
Artificial Intelligence Competition

Offline Cloudee1

Re: running into a running problem (bad joke lol)
« Reply #3 on: June 23, 2012, 07:11:43 PM »
How about throwing both tidbits away and just handleing it with the if said run statement. add in an extra if statement... if send gego is moving then send gego setmotion walk to wherever he was heading... i'm pretty sure there are some variables that already exist you can just stick in for x and y.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Doan Sephim

Re: running into a running problem (bad joke lol)
« Reply #4 on: June 23, 2012, 09:07:26 PM »
How about throwing both tidbits away and just handleing it with the if said run statement. add in an extra if statement... if send gego is moving then send gego setmotion walk to wherever he was heading... i'm pretty sure there are some variables that already exist you can just stick in for x and y.
That's exactly the snag. You said add in an extra if statement. The precise formulation of that if statement is what I am struggling with at current. you wrote "if send gego is moving" but then I need to find the way to differentiate between where ego is headed via mouse button (which has a definitive x and y value), and the keyboard which doesn't. I know how to send gego in motion in both cases, I just don't know the precise formula of the if statement. I'm sure its simple enough, but it still eludes me.


Offline gumby

Re: running into a running problem (bad joke lol)
« Reply #5 on: June 25, 2012, 09:55:50 PM »
If I understand the problem correctly, how about whenever the mouse is clicked (resulting in movement), set a variable with the point that was clicked (okay, maybe 2 variables, x and y).  Do the same with when the keypad is used, setting a different variable, but with a 'keypad' directional value.  Every time you use the keypad for movement, wipe out any saved value in your 'mouse' variable, and the reverse (wipe out your stored 'keypad' variable when the mouse is clicked).

Then you'll be able to use the variables to determine what the last movement was entered with.  That would be the input for your missing 'if'.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Doan Sephim

Re: running into a running problem (bad joke lol)
« Reply #6 on: June 28, 2012, 11:43:14 PM »
If I understand the problem correctly, how about whenever the mouse is clicked (resulting in movement), set a variable with the point that was clicked (okay, maybe 2 variables, x and y).  Do the same with when the keypad is used, setting a different variable, but with a 'keypad' directional value.  Every time you use the keypad for movement, wipe out any saved value in your 'mouse' variable, and the reverse (wipe out your stored 'keypad' variable when the mouse is clicked).

Then you'll be able to use the variables to determine what the last movement was entered with.  That would be the input for your missing 'if'.

Yup, that did the trick. I set up a new global variable "gRunClick" and headed over to the User Script, which is where we will find the code for moving the Ego.

One minor bug to fix. When ego is standing still and you type run he will head off. So it will be necessay to add one more if statement: (if(not(send gEgo:isStopped())) does it just fine :)

Code: [Select]
(method (handleEvent pEvent)
(var direction)
(if( not (super:handleEvent(pEvent)) )
    (switch( (send pEvent:type) )
(case evMOUSEBUTTON
// 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)
   )
    )
                                = gRunClick 1
    (User:prevDir(CENTER))
    (send pEvent:claimed(TRUE))
)
)
  (case evJOYSTICK
  = direction (send pEvent:message)
  (if( (== direction (User:prevDir)) and (IsObject(mover)))
    = direction CENTER
    )
                    = gRunClick 0
    (User:prevDir(direction))
    (self:setDirection(direction))
    (send pEvent:claimed(TRUE))
  )
  )
  )
  return(send pEvent:claimed)
)

I added the = gRunClick 1 or 0 depending on the nature of the players movement choice (1 for mouse click and 0 for keypad).

After that is done, I headed back to the main Script:

Code: [Select]
(if(Said('run'))
(if(not(gEgoRunning))
                    (send gEgo:view(230)xStep(5)yStep(4))
                    = gEgoRunning 1
                    (if(gRunClick)
                        (send gEgo:setMotion(MoveTo (send pEvent:x)(send pEvent:y)))
                    )(else
                        (switch (send gEgo:loop)
                            (case 0
                                (send gEgo:setDirection(RIGHT))
                            )(case 1
                                (send gEgo:setDirection(LEFT))
                            )(case 2
                                (send gEgo:setDirection(DOWN))
                            )(case 3
                                (send gEgo:setDirection(UP))
                            )
                        )
                    )
                )(else
                    Print(0 39)
                )
            )
Now if Ego is in motion and the player types run it will send Ego in the right direction at running speed!
« Last Edit: June 30, 2012, 09:52:31 PM by Doan Sephim »
Artificial Intelligence Competition

Offline totenmaske

Re: running into a running problem (bad joke lol)
« Reply #7 on: July 01, 2012, 05:55:07 AM »
After reading this i had a thought, does anyone know how to change to view of gEgo when you are using the Home, End, Page Up and Page Down buttons? Would be nice to have a better loop so when people use that function it doesn't look so... (I can't think of the right word at the moment).


SMF 2.0.14 | SMF © 2017, Simple Machines
Simple Audio Video Embedder

Page created in 0.128 seconds with 24 queries.