ID:261933
 
The below code snippet is supposed to carry out the following actions when you go to drop the block you are carrying: Check the tile in front of you for anything that is dense. If it finds either one, it will then move to the tile above and look for the same things. But this time, if either is found, it does nothing. And on either one, if nothing is found, you set the block down in that place.

The problem: If I leave the first FOR LOOP where it's at, it does nothing at all, no message, no lifting, nothing. If I put the first FOR LOOP as the second loop, it gives me the message, but that's no good either because that means it failed, and it always fails the same way -- check 1 = 0, check 2 = 1, check 3 = 0. And finally, if I use the first FOR LOOP as the last check, it will lift any block up no matter it's position.


mob
proc
Pickup()
var/turf
T = get_step(src,NORTH)
Tu = get_step(src,src.dir)
A = get_step(Tu,NORTH)
var/obj/block/B
var
chk=0; chk2=0; chk3=0
if(T.density) return
if(A.density) return
for(var/obj/block/C in Tu) //Is there a block in front of him. FOR loop 1
if(C)
chk=1; B=C; break
for(B in T) //Is the tile above blocked?
if(!B)
chk2=1; break
for(var/obj/block/D in A) //Is there a block above the block in front of him?
if(!D)
chk3=1; break
if(!B) return
if(chk && chk2 && chk3 == 0)
BUG("Error. Check 1: [chk]; Check 2: [chk2]; Check 3: [chk3]"); return
else
src.ac = 1
B.Pickup(T,src)

Okay, before I can help, I want to see if I get this straight:

You have a proc that is allowing players to drop 2x2 blocks. The block can be placed in two patterns, depending on the direction you are facing:
 XX
>X

XX
X<

What you want is a system for figuring out whether or not you can place the 4 block obj's in those locations.

Right?
In response to Garthor
No no no... Sorry about not explaining myself well. So here I go.

It's a side view game.

the object is to pick up 1 tile blocks and move them around so you can make your way across the level. Thus, it's a puzzle game.

Now, the code is supposed to check above you for anything dense, namely a turf. If a turf is there then it won't let you pick up the block that is 1 tile front of you. It also checks to see if a block is infact, in front of you, if not, the proc cancels. The last thing it is supposed to do is check if another block sits on top of the block that you are tying to pick up, if there is, then you can't pick up the block.

# = block
X = player
_ = dense turf

This would be a succesful way to pick up a block: # X## ->
#
# X # <-- End result

This wouldn't work:
_
# X##

Neither would this:
#
# X#
In response to Resonating_Light
Okay, I get it now, so you want the game to ask two things:

1. Can this block be lifted upwards?
2. If so, can it be placed above the person lifting it?

Fortunately, it's rather simple. Just use Enter().
mob/Bump(var/obj/block/B)
if(istype(B)) //If the variable's type is correct
var/D = get_dir(B, src)
var/turf/T1 = get_step(B, NORTH)
var/turf/T2 = get_step(T1, D)
if(T1 && T2) //Gotta make sure they exist
if(T1.Enter(B) && T2.Enter(B))
src.frozen = 1
B.step(NORTH)
sleep(2)
B.step(D)
src.frozen = 0

A lot simpler, isn't it?

Make sure the Enter() proc doesn't actually CHANGE anything. All it should do is return 1 or 0. Same with Exit().

Also, setting the animate_movement var to SLIDE_STEPS may make it look better. Try that, and try adjusting the sleep(). It'll make it look somewhat like you're actually picking it up.
In response to Garthor
Thanks a lot. I never even thought of using Enter(), and yes, it's much simpler.
[edit]
You did step wrong though. lol. It's..
step(ref,dir)
[/edit]