ID:1086919
 
(See the best response by Jemai1.)
Code:
var/time
var/dice="1d6"
obj
dice
icon='Dice.dmi'
icon_state="animation"
New()
walk_rand(src,0,5)
spawn(5)
walk(src,0)
var/h = roll(dice)
if(h==1)
icon_state="1"
walk(usr,usr.dir,0.5,2)
usr.moving=1
time=6.5
spawn(time)
walk(usr,0)
usr.moving=0
if(h==2)
icon_state="2"
walk(usr,usr.dir,0.5,2)
usr.moving=1
time=6.5*2
spawn(time)
walk(usr,0)
usr.moving=0
if(h==3)
icon_state="3"
walk(usr,usr.dir,0.5,2)
usr.moving=1
time=6.5*3
spawn(time)
walk(usr,0)
usr.moving=0
if(h==4)
icon_state="4"
walk(usr,usr.dir,0.5,2)
time=6.5*4
spawn(time)
walk(usr,0)
if(h==5)
icon_state="5"
walk(usr,usr.dir,0.5,2)
usr.moving=1
time=6.5*5
spawn(time)
walk(usr,0)
usr.moving=0
if(h==6)
icon_state="6"
walk(usr,usr.dir,0.5,2)
usr.moving=1
time=6.5*6
spawn(time)
walk(usr,0)
usr.moving=0

mob
verb
Dice()
var/obj/dice1 = new /obj/dice
dice1.loc=locate(5,5,1)


Problem description: I'm making a Snakes and Ladders game, my problem is that when a player gets to the end of a raw , he doesnt go up, for example he goes from 1 to 10 then he should go p to 11 but he doesnt, so im struggling with this issue, Thanks

Well, this isn't related to the issue presented, but I thought I'd just point out this:

var/time
var/dice="1d6"
obj
dice
icon='Dice.dmi'
icon_state="animation"
New(mob/m)//define the usr as m, you don't usually want to use 'usr' in procs like this.
walk_rand(src,0,5)
spawn(5)
walk(src,0)
var/h = roll(dice)//Instead of the 6 if() checks, you should've condensed it like this, and if you couldn't- you should've probably used switch()
icon_state="[h]"
walk(m,m.dir,0.5,2)
m.moving=1
time=6.5*h
spawn(time)
walk(m,0)
m.moving=0
mob
verb
Dice()
new/obj/dice(locate(5,5,1), usr)


Sorry, this is just a quick edit/redo of your code. Not sure if I made a mistake myself in this, I have company over so I don't wanna waste a lot of time on this.
aiight thanks
Best response
The problem is that you keep walking on the same direction. You should change the direction of movement once you reach the end of the map.
i tried that, i used several methods one is this walk(M,M.dir,0.5,2) and in Entered() i change the dir to NOrth and in Exited() i change it back to EAST or west. however none of my methods worked
What you should be using is a step loop instead of walk. On each step, change the dir when necessary.
that sounds like an idea, but can u show me the loop in a code line so i can fully understand it? thanks
mob
verb
Dice()
var/steps = roll("1d6")
// animate dice here
for(var/i in 1 to steps)
sleep(2) // delay
if( y%2 ) // odd row
if( x == world.maxx ) // end of row
dir = NORTH // go up
else
dir = EAST // go right
else // even row
if( x == 1 ) // end of row
dir = NORTH // go up
else
dir = WEST // go left
step(src,dir)
// handle snakes and ladders here


Another approach is to do this on initialization of the map by giving the turf a "next" variable.
turf
var/turf/next

New()
..()
var/dir
if( y%2 ) // odd row
if( x == world.maxx ) // end of row
dir = NORTH // go up
else
dir = EAST // go right
else // even row
if( x == 1 ) // end of row
dir = NORTH // go up
else
dir = WEST // go left
next = get_step(src,dir)

// Then, move your player according to the next var
mob
verb
Dice()
var/steps = roll("1d6")
for(var/i in 1 to steps)
sleep(2)
var/turf/turf = loc
if(turf.next)
Move(turf.next)
else
src << "You reached the end of the board"
break
was just wondering where should i handle the movement of the player?
There are different ways. To restrict movement via arrow keys, you can do so by overriding client.Move()
client
Move()
// do nothing
i dont mean that, i mean when the player moves depending on the number and the side of the dice, for example this old movement system

obj
dice
icon='Dice.dmi'
icon_state="animation"
New(mob/m)//define the usr as m, you don't usually want to use 'usr' in procs like this.
walk_rand(src,0,5)
spawn(5)
walk(src,0)
var/h = roll(dice)//Instead of the 6 if() checks, you should've condensed it like this, and if you couldn't- you should've probably used switch()
icon_state="[h]"
walk(m,m.dir,0.5,2)
m.moving=1
time=6.5*h
spawn(time)
walk(m,0)
m.moving=0



In response to Sers000
Please tell me you didn't copy/paste my re-write.
If you mean the moving variable, you can set it before and after the loop.
@NNAAAAHH yes i did, just to help jemai understand it easier mine is too long and the way u did it is better. hopefully ur not annoyed lol
@Jemai1 , not the moving variable i mean the whole movement system that starts the moment u throw the dice, it check the side and moves equal steps to the side for ex side 5 will make it move 5 blocks, my main problem is for example block 10 is the last one in the row, so i threw the dice and i got 5 and im at block 8, i have to move 9>10 then go up 11 then go right 2 more steps 12<13. my problem si that it doesnt go up and when i managed to make it go up, it either stops or continue to infinity.
The example I have provided already does that.
this is what the code did, i press Dice verb and after 2/10 secs i get the message "You reached the end of the board". and the player doesnt move he keeps at block number 1
just to let u know, i tried the second one not the first method
this is what i have :
 

turf
var/turf/next
ten
icon='Tabuleiro.dmi'
icon_state="10"
New()
..()
var/dir
if(y%2)
if( x == world.maxx)
dir = NORTH
else
dir = EAST
else
if(x == 1)
dir = NORTH
else
dir = WEST
next = get_step(src,dir)



mob
verb
Dice()
var/steps = roll("1d6")

for(var/i in 1 to steps)
sleep(2)
var/turf/turf = loc
if(turf.next)
Move(turf.next)
else
src << "You reached the end of the board"
break
You do that to all of your turfs not just the tenth.
Page: 1 2 3