Author Topic: Using the avoid script  (Read 22402 times)

0 Members and 1 Guest are viewing this topic.

Offline Cloudee1

Using the avoid script
« on: May 10, 2010, 09:43:01 AM »
So I know I've seen it before, I'm pretty sure I have even played around with it. But for the life if me I can't find or remember how to tell an actor how to use the avoid script. Anybody else remember how to do this?


Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline MusicallyInspired

Re: Using the avoid script
« Reply #1 on: May 10, 2010, 10:14:03 AM »
I posted my own questions about this ages ago and never got an answer. How I wish we had members who knew SCI code backwards and forwards....
Brass Lantern Prop Competition

Offline Cloudee1

Re: Using the avoid script
« Reply #2 on: May 10, 2010, 11:25:55 AM »
I may have figured it out, but I'm not positive because of the way Ilm wanting to use it. In the actors init, or whenever you start them walking, add in doAvoider() that seems to be the correct command anyway. Unfortunately I want to use it in conjunctio with follow and follows doit method, I think, is overriding it so it never actually gets a chance to avoid anything. It should work though in a moveto situation but alas thats not what I am doing. A sloppy workaround might be to add in a changestate where case 0 is a couple of cycles, case 1 moves to egos x y while avoiding and when it reaches x and y go to case 3 which just has a command to go to case 0 again. the obvious drawbacks of course would be if you changed directions the following character wouldn't update until it reached the last point so it might look funny. As for adding it to ego I think it would work fine to add it in when the room inits the ego.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline troflip

Re: Using the avoid script
« Reply #3 on: January 06, 2011, 02:50:36 AM »
I know this is an old question, but just do:

Code: [Select]
(send badguy:setAvoider(Avoid))
where badguy is an object of type Act, and of course you need the Avoid script which isn't in Brian's original template game.
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Collector

Re: Using the avoid script
« Reply #4 on: January 06, 2011, 04:01:03 AM »
I am not sure how much work it would be to create a new template game, but it seems that there are certain limitations with it. I would expect that QfG2 would have a more robust parser.
KQII Remake Pic

Offline Cloudee1

Re: Using the avoid script
« Reply #5 on: January 17, 2013, 10:50:32 PM »
Still just won't quite work. Here is the code I am using to init my goat who is supposed to be following the ego. This first bit of code has some serious issues, as soon as the goat hits a white control line he immediately heads off towards 2:00 and never looks back, not even when he hits another white line and it also throws an OOPS error when attempting to leave the screen.

Code: [Select]
(goat:init()
        setCycle(Walk)
        setAvoider(Avoid)
        setMotion(Follow gEgo 30)
        posn(320 (send gEgo:y))
        loop((send gEgo:loop))
)

So a couple of variations, this does not throw an oops error, but no avoiding takes place.
Code: [Select]
setAvoider(ctlWHITE)
And finally, we have this one. This time, there is avoiding taking place but we are back to the oops error when exiting the screen
Code: [Select]
setAvoider(Avoid ctlWHITE)
All three variations compile without error, just none of them work. If anyone could help me figure this out, I would appreciate it.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Using the avoid script
« Reply #6 on: January 18, 2013, 08:04:58 AM »
Return of the Black Cauldron?  :). I'll play around with the avoid script this weekend.  Can you elaborate on what you are trying to do?  It looks like you have the goat following the ego but want the goat to get out of the way when it you move toward it?
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Using the avoid script
« Reply #7 on: January 18, 2013, 05:17:21 PM »
I want the goat to try and unstick itself when it gets caught on the white control line of trees, rocks, and other obstacles while following the ego.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Using the avoid script
« Reply #8 on: January 18, 2013, 10:13:01 PM »
Is there a way to get the Avoid script to work without the Follow script?  Here's what I have:

Code: [Select]
(doppleganger:init()
        setCycle(Walk)
        setAvoider(Avoid)
        setMotion(MoveTo 20 202)
)

I set up a white control line in the actor's path, and it just stops when it hits it.  In this context, the avoid script doesn't seem to do anything.

Was the avoid script designed specifically to only be used in conjunction with the follow motion?
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Collector

Re: Using the avoid script
« Reply #9 on: January 18, 2013, 10:45:32 PM »
This was one of the improvements with later versions of SCI. Vastly improved walk paths, which I assumed was partly because of improved control/interaction of things like control lines. The characters didn't get hung on winding paths.
KQII Remake Pic

Offline gumby

Re: Using the avoid script
« Reply #10 on: January 18, 2013, 11:40:44 PM »
The Avoid script looks incomplete.  I'm seeing 'goto' calls commented out:

in the doit()
Code: [Select]

            (send theMover:doit())

            (if (== (send client:x) clientX)
                (if (== (send client:y) clientY)
                    // goto code_0254                                 // unimplemented code here
                )(else
                    (self:pickLoop(angle))
                    return (++nonBumps)
                )
            )(else
                (self:pickLoop(angle))
                return (++nonBumps)
            )


and again here:
Code: [Select]
       // Increment our position! Finally!
        (self:incClientPos())

        (if (self:canBeHere)
            // If I can be here, then increment the number of nonbumps.
            // and we're done (unless we are escaping)
            (++nonBumps)
            (= bumpTurn 0)
            (if (escaping)
                // goto code_037F;                                   // unimplemented code here
            )(else
                return
            )
        )(else
            // Uhoh... we can't be here.
            (= lastBumped bumpTurn)
            (= bumpTurn thisTurn)
            (= nonBumps 0)
        )

Although, why would the Avoid.sc script be included in the template game if it didn't work.  Maybe we are just missing something.
« Last Edit: January 18, 2013, 11:43:15 PM by gumby »
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline gumby

Re: Using the avoid script
« Reply #11 on: January 19, 2013, 10:20:06 AM »
Anyone implement the avoid script successfully in any of their games?  I've checked all the available source code of the fan games here, none of them have used it.

BTW:  Cloudee, I have successfully reproduced your 3 scenarios (and results) as you posted earlier in a single one-room game.  Note that example 2 is not valid, you do need to specify 'Avoid' as the first argument - similar to a call to the setMotion class (e.g. Follow, MoveTo). I'm not sure about specifying a control color for the 2nd argument as you did here:

Code: [Select]
  setAvoider(Avoid ctlWHITE)

The 2nd parameter of the Avoid script maps to the 'offScreenOK' parameter of the script, but I'm not sure what that parameter does (yet).
« Last Edit: January 19, 2013, 10:31:34 AM by gumby »
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Using the avoid script
« Reply #12 on: January 19, 2013, 11:24:37 AM »
That's unfortunate too. As the version with avoid and the control color was the version that came the closest to working. There was at least some avoiding going on in that scenario.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Using the avoid script
« Reply #13 on: January 19, 2013, 12:19:36 PM »
I tried several different tests.  What's strange is I can always have the actor avoid the first contact of the white control color but any subsequent contact with a white control line the actor ignores and just keeps on going off-screen.

Once I was able to get the actor to observe contact with a second white control line, but now I can't reproduce it.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Using the avoid script
« Reply #14 on: January 20, 2013, 02:13:41 PM »
Unfortunately it is imperative that I get some sort of path finding working in this project. To that end, it looks like I am going to have to write my own...

Not real sure that is something that I am up to. We'll see how it goes.

Right now, I have the goat actor all set up in a region script. So for now, I plan to build my pathfinding into that script which handles all of the goats code. I have done some preliminary tests to try and gather some useful information while I walk around with my goat in tow. I am using the avoid script's variables where I can to see what it is that they tell me. Some of them don't seem to tell me anything.

Code: [Select]
(local
theMover // not real sure what this gives me, doesn't seem useful by itself
moverX // based off of theMover.. seems to reflect the target x
moverY// base off of theMover... seems to reflect the target y
theStatus // tells me if goat can be where it is
theStatus2 // tells me if goat can be where ego is
currentCtl // the current control color the goat is on
angle // the angle between where the goat is and the ego
)
Then in the handleEvent method so I can see my values.
Code: [Select]
= theMover (goat:mover)
= moverX (send theMover:x)
= moverY (send theMover:y)
= theStatus (goat:canBeHere((goat:x) (goat:y)))
= theStatus2 (goat:canBeHere(moverX moverY))
FormatPrint("The Mover: %d,\nmoverX: %d  y: %d\nGoatX: %d  y: %d\ncanBeHere: %d\ncanBeThere: %d" theMover moverX moverY (goat:x) (goat:y) theStatus theStatus2)
   

    = currentCtl (goat:onControl())
    = angle (ClampAngle(GetAngle((goat:x) (goat:y) moverX moverY) 360))
FormatPrint("Control: %d\nStopped: %d\nAngle: %d" currentCtl (goat:isStopped) angle)
   
and at the end of the script, a clampAngle procedure, copied straight from avoid
Code: [Select]
(procedure (ClampAngle param1 param2)
    (= param1 (- param1 (* param2 (/ param1 param2))))
    (if (< param1 0)
        return (+ param1 param2)
    )
    return (param1)
)
Some things I have noticed so far. For 1, if the goat is hung up and still trying to walk, isStopped returns FALSE. As long as the goat is trying to move, it is not stopped. I need to figure out a way to check all points between where the goat is and where ego is because both of those values for canBeHere return true which makes sense because I'm checking where they are and they are in good spots or the game wouldn't let them be there. So those values tell me nothing.

I am thinking that in the end, I will probably drop the use follow from this script, and instead try to determine a path to the ego. Then I will set up a doit method with a setMotion dPath that leads to the ego around obstacles.

What I think the logic needs to be...
1. Get ego Posn.
2. Get goat Posn.
3. Determine angle between Posns.
4. Check path along angle
5. If can be here all along path, setmotion.
 ... this is where I am still pondering.
either get posn of first false and guess different directions to try and get there
try going a different direction left then down or whatever until I find a way through
but basicly I want to find a path before I setMotion.
15. if ego posn change, go to 1.
« Last Edit: January 20, 2013, 05:28:26 PM by Cloudee1 »
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


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

Page created in 0.031 seconds with 19 queries.