ID:179194
 
Guys I'm shooting in the dark here, so any tips on where to look are appreciated - most likely this has been covered in some form or fashion...

I'm slowly playing with my StarTrek idea (called at this point StarWreck - subject to change of course). Yesterday I made a little Enterprise-D icon zip around a small space map - very cute. Today I was noodling through the Forums, and came across Spuzzum's rotate verb for a catapult, and implemeted this into my code:

//ship movement verbs
verb/Rotate_Left()
src.dir = turn(src.dir,45)
verb/Rotate_Right()
src.dir = turn(src.dir,-45)

that worked easy enough, so I moved on to the idea of 'Impulse' and 'Warp' speed. A look into the Help files, and I came up with this:

verb/Half_Impulse()
walk(src, src.dir, 5)
verb/Full_Impulse()
walk(src, src.dir, 1)
verb/Stop()
walk(src, src.dir, 0)

I found Foomer's 'setting a mobs speed' post, but thought that the above would be more effective - and it partially works: when you click on either the 'Half Impulse' or 'Full Impulse' verb, the Enterprise dutifully takes off in the direction it is facing. Joy!

But there are a few curious problems: 1) the 'Stop' verb does not stop the ship, but hitting a direction key does; 2) When clicking on one of the 'Rotate' verbs while under "Impulse power", the ship rotates briefly then returns to facing and moving in the heading that the Impulse verb had originally set.

Bug? Undocumented Feature? Or just an improper use of the code?

---------------------
[email protected]
digitalmouse wrote:
But there are a few curious problems: 1) the 'Stop' verb does not stop the ship, but hitting a direction key does; 2) When clicking on one of the 'Rotate' verbs while under "Impulse power", the ship rotates briefly then returns to facing and moving in the heading that the Impulse verb had originally set.

Bug? Undocumented Feature? Or just an improper use of the code?

I have yet to use walk() for anything, but from what I know the problem is that it sets the direction for you while it walks, and keeps walking until you tell it to stop. What you need to do is use a var to keep track of which impulse power the ship is using (if any), and call walk() again after you rotate it.

Lummox JR
I've never used "walk()" for anything but stopping a currently active walking, but if you want your code to do what you want it to do, you might try something like this instead:

mob/var/impulse = 0
verb/Half_Impulse
impulse = 5
spawn() Impulse()
verb/Full_Inpulse
impulse = 1
spawn() Impulse()
verb/Stop()
impulse = 0
spawn() Impulse()

proc/Impulse()
for()
if(!impulse) return
sleep(impulse)
step(src,src.dir)

The result: It will take a step in whatever direction it is facing continually in the for() loop, if you change directions it will start stepping in that direction instead. It will delay each loop for a time equal to the amount of impulse it has, and if impulse is 0, it will stop the loop alltogether.

I say if it doesn't work right, avoid it :oP
verb/Stop()
walk(src, src.dir, 0)

Although Foomer's code is good, and probably a better way of going about doing this, if you want to keep this setup, you should be able to fix it with:

verb/Stop()
walk(src, 0)

You were close, but the format to stop walk() is slightly different.

-AbyssDragon
Also, if you're going to be making your own movement procs, you want to overwrite client.Move() (the proc that handles what happens when a direction key is pressed), or there's nothing to stop players from getting fed up with rotating and impulse speed and just moving the ^$@! ship themselves.

You could even, if you were so inclined, overwrite client.East() and West() to call your rotate procs, and overwrite North() and South() to scale up and down through the levels of impulse.
In response to AbyssDragon
Could probably do something like this too:

verb/Half_Impulse()
walk(src, 0)
walk(src, src.dir, 5)
verb/Full_Impulse()
walk(src, 0)
walk(src, src.dir, 1)
verb/Stop()
walk(src, 0)
In response to Foomer
Foomer wrote:
Could probably do something like this too:

verb/Half_Impulse()
walk(src, 0)
walk(src, src.dir, 5)
...

Hmmm...looks ok, but I would expect a more jerky movement that what is happening now with changing the walk speed to 0 then to 5 over and over, but I could be wrong...

I do like the mob/var/impulse solution that you and Lummox talked about - works better in my little demo...ironically I did basically the same thing in a VB version of this idea (I dug out that code last night after trying out your ideas). But my VB code dealt with pixel-based movement (moving the ship icon 'x' number of pixels according to a speed setting) - I don't suppose that byond supports this yet? If not, too bad, for it lends to smoother movement of the ship...

AbyssDragon wrote:
verb/Stop()
walk(src, 0)
You were close, but the format to stop walk() is slightly
different.

I corrected the code and it worked, stopping the ship properly. But I decided that Foomer's code snippet did the job better (as yourself pointed out).

LesbianAssasin wrote:
you want to overwrite client.Move() (the proc that
handles what happens when a direction key is pressed), or
there's nothing to stop players from getting fed up with
rotating and impulse speed and just moving the ^$@! ship > themselves.

Right! And that was my intention after the above problem was dealt with. I will be overwriting the client.East(), etc., procs with my own routines, and setting up key macros for various functions (phasers, torpedoes, tractor-beam, communication, etc.)

----
Folks, you have again helped a newbie in need, and I am grateful for the numerous responses! With you people helping me shift my Java and PHP thinking to byond, I should have a little StarTrek game available in no time!

Thanks again...
[email protected]
http://www.digitalmouse.org/
In response to Lesbian Assassin
Lesbian Assassin wrote:
You could even, if you were so inclined, overwrite client.East() and West() to call your rotate procs, and overwrite North() and South() to scale up and down through the levels of impulse.

Are you referring to something like:

mob

verb/Rotate_Left()
src.dir = turn(src.dir, 45)

client.East()
Rotate_Left()
..()

???