ID:267067
 
At my game, there is ice. Simple. Now i want the ice to make you slide and not be able to move any other direction until it hits a dense object. Not so simple to me. I would appreciate any help from you BYONDers!
To figure out what you need to do, think about each step necessary to complete the overall task and don't worry about the actual code yet.

To slide in one direction until something dense is hit you need to:
1) know which direction to slide
2) know where sliding in that direction will take you
3) find out if you can slide there (can't if it's dense)
4) if you can slide, then move to that new location
5) repeat 1-4 until you can't slide any further

Solutions:
1) This depends on how you handle movement, but I'd guess you want to move in the direction the mob is facing after its first move (you take a first step on the ice, then keep sliding in that direction). You could do that first step by using Move() which sets the direction you will be sliding in.
2) You can find where you are moving to by looking at the next location in the direction you are moving, which can be accomplished by get_step().
3) You can find out if the next location is dense directly, or you can rely on the Move() proc to check it automatically.
4) Use Move() to go to the new location.
5) Use a loop to move all the way, or keep calling Move() until something dense is hit.

Move()
if(..()) Move(get_step(src,dir)) //..() returns 1 if the move was successful, which means it wasn't blocked by anything dense. If it wasn't blocked, then move to the next location.


Another possibility, assuming the mob is already facing the right direction:

mob/proc/Slide()
var/nextloc
do
nextloc = get_step(src,dir)
while(Move(nextloc)) //Move() returns 1 if the move was successful, and 0 if it was not

The only problem with both of these examples is that the movement will be nearly instantaneous, meaning they will appear to jump to their destination without showing each slide. You can force it to show each step by using spawn() or sleep().
In response to English
English wrote:

Move()
if(..()) Move(get_step(src,dir)) //..() returns 1 if the move was successful, which means it wasn't blocked by anything dense. If it wasn't blocked, then move to the next location.

Actually, you might want to put that under turf/slippery/Entered() instead. Then, when you hit something dense, you don't Entered() anything (mention the obvious grammer flaw there and I'll kill you) and thus you stop, ready for another movement. So...

<code> turf/ice Slippery = 1 turf Entered(mob/M) if(Slippery) M.slipLocked = 1 if(!step(M,M.dir)) //If the step fails M.slipLocked = 0 mob Move(NewLoc,Dir) if(slipLocked) if(dir == Dir) //Dir being the direction moving, dir being the usr's direction ..() //Then you can move else return 0 //Otherwise, you can't else ..() </code>

If you don't understand any part of that, I very strongly suggest you ask about it.
In response to Garthor
Just a few things you, uh, "slipped" up on there Garthor... ;-)

- mob/var/sliplocked isn't defined
- You need to set the return value in Move(); i.e. .=..() rather than just ..()
- turf/var/Slippery isn't defined

So the modified code becomes:
<code> turf/ice Slippery = 1 turf var/Slippery Entered(mob/M) if(Slippery) M.slipLocked = 1 if(!step(M,M.dir)) //If the step fails M.slipLocked = 0 mob var/slipLocked Move(NewLoc,Dir) if(slipLocked) if(dir == Dir) //Dir being the direction moving, dir being the usr's direction .=..() //Then you can move else return 0 //Otherwise, you can't else .=..() </code>
(BTW, I like your approach to this Garthor. Very slick.)
In response to Garthor
Uhh, when i put that code in, there were some errors. Here are they:


turfs,objs,areas.dm:150:error:slipLocked:undefined var
turfs,objs,areas.dm:139:error:Slippery:undefined var
turfs,objs,areas.dm:143:error:Slippery:undefined var
turfs,objs,areas.dm:144:error:M.slipLocked:undefined var
turfs,objs,areas.dm:146:error:M.slipLocked:undefined var

I think you forgot to include some variables...
In response to Unknown Person
If you do not know how to define varibles, you shouldn't doing something this complicated which isn't that complicated.
In response to Crispy
Crispy wrote:
Just a few things you, uh, "slipped" up on there Garthor... ;-)

I forgot about the . = ..() thing in Move(). Also, I try not to provide entirely complete code. If they can't figure out how to fix the errors, then too bad. Which is my excuse for not really caring to double check my code.

(BTW, I like your approach to this Garthor. Very slick.)

Pun intended?