ID:165521
 
no built in procs seem to work... i tried Click() and it didn't work, no one could help. I had a bad experience with New() once, i was lucky i didn't have to post about it before i solved it. i'm lucky leven Login() and Logout() work...
Well can anyone help me this time with direction procs? i wanted something like this:
mob
Old_Man
icon = 'old_man.dmi'
icon_state = "normal"
Wander()
proc
Wander()
var/wanderproc = rand(1,4)
if(wanderproc == 1)
North()
sleep(10)
Wander()
if(wanderproc == 2)
East()
sleep(10)
Wander()
if(wanderproc == 3)
South()
sleep(10)
Wander()
if(wanderproc == 4)
West()
sleep(10)
Wander()

but the directional procs aren't working for me! it just gives me a warning that says the direction is an "unused label". these procs could make the difference between my noobiest game ever and a work of art, so please explain!
Actually READ the reference entry for procs before you do anything with them. Also read the DM Guide.

The built in procs are working fine; it's just that you can't code properly. :)

The North(), South() etc procs are CLIENT procs. They're called when the player issues the respective direction command, and aren't even meant to be manually called.
Anyway, you want the atom/movable/Move() proc (NOT client/Move(), mind you).
I'm not 100% sure but i think that you can't use East() and stuff inside a proc but only inside client, again, I'm not 100% sure but all the example's involving those procs i only see in client. Sorry if I'm wrong
In response to Kaioken
Kaioken wrote:
Actually READ the reference entry for procs before you do anything with them. Also read the DM Guide.

The built in procs are working fine; it's just that you can't code properly. :)

The North(), South() etc procs are CLIENT procs. They're called when the player issues the respective direction command, and aren't even meant to be manually called.
Anyway, you want the atom/movable/Move() proc (NOT client/Move(), mind you).


wow i was typing my message when this came up, i guess that renders mine useless.
In response to Kaioken
okay, so i know what i'm doing wrong, anyone care to show me how to do it right? if i could just understand this...
In response to Adam357
Gee, do a little effort for yourself... I told you what you need to use instead, the atom/movable/Move() proc. Anyway, as you proved, you don't want to make effort for yourself, so I will actually help you so this post isn't useless; here's your code, shortened, optimized, fixed...in one word, pretty much -normalized. :D
mob
Old_Man
icon = 'old_man.dmi'
icon_state = "normal"
//Wander() <-- That's useless, if you want the proc to execute when the object is created, execute it on New()
proc/Wander()
for() //create an infinite loop
step(src,pick(NORTH,EAST,WEST,SOUTH)) //easier shortcut for 'src.Move(get_step(src,pick(NORTH,EAST,WEST,SOUTH)))'
sleep(10)


Note that the direction numbers are bit-flags, and the values arent just 1-4; they're as follows:
N==1 , S==2 , E==4 , W==8
NE==5 , NW==9 , SE==6 ,SW==10

In addition, provided you don't mind diagonal movement, that whole proc is obsoleted by the built-in walk_rand proc.

Also, you should have a 'main' path for NPCs. Otherwise, if you want multiple types of mobs to have this proc, you'd have to duplicate it for each - which is stupid.
In response to Kaioken
thanks, that works, but it lags like hell. are you sure theres nothing more efficient i can do?
In response to Adam357
You're welcome.

It shouldn't lag, you're probably doing something wrong. How are you activating it? You're possibly activating it multiple times.
In response to Adam357
nevermind, that works. i forgot to put sleep() in the infinite loop, so it was causing havoc with the runtime. thanks!
WAIT!! no it didn't!! after a while of looping it stops, and comes up with a huge list of call stack, and this!
runtime error: Maximum recursion level reached (perhaps there is an infinite loop)

HUH!? i guess infinite loops don't like me.
In response to Adam357
Post your code (post the Wander proc if you altered it from my posted one, and also regardless post the code where you call that proc).
In response to Kaioken
is this all you need?
    proc
Wander()
for()
step(src,pick(NORTH,SOUTH,EAST,WEST))
sleep(5)
Wander()
Old_Man
atom/movable/Move()
icon = 'old_man.dmi'
icon_state = "normal"
New()
Wander()
In response to Adam357
You probably want a proc, so you can do that to multiple things.
atom
movable
proc
StepCardRand()
while(1)
step(src,pick(directions)
sleep(10)
var
list
directions = list(1,2,4,8)

In response to Xx Dark Wizard xX
Please don't post code on the forum that's going to be indented by only one space. It's only barely readable. Use at least two spaces, or a tab.

Lummox JR
In response to Xx Dark Wizard xX
good idea, so where do i put this? (sorry, im sure it seems like im not thinking for myself here, but im a noob at this! thats why i ask you for help - to learn BYOND coding.)
mob
Old_Man
icon = 'old_man.dmi'
icon_state = "normal"
New()
..()
walk_rand(src,3)
In response to Adam357
Adam357 wrote:
is this all you need?
>   proc
> Wander()
> for()
> step(src,pick(NORTH,SOUTH,EAST,WEST))
> sleep(5)
> Wander() //<-----BAD
> Old_Man
> atom/movable/Move()
> icon = 'old_man.dmi'
> icon_state = "normal"
> New()
> Wander()
>


Sigh, just as I suspected. As I said, for() already creates a loop (in that case, an infinite one). You are re-calling Wander() in each iteration, so of course it freezes.
Really, think before you do things. I added comments for you to read them, not to ignore them.


@SSJChao: That would work, I already mentioned that, but I gathered he wanted only the 4 cardinal directions to be used, and the walk_rand() proc uses diagonals as well, so there is a need to make a new proc.
In response to Kaioken
atom
movable
proc
StepCardRand()
while(1)
step(src,pick(directions))
sleep(10)
var
list
directions = list(1,2,4,8)


And you call that like,
mob
Person()
New()
..()
StepCardRand()

That is like walk_rand except it only uses cardinal directions.
In response to Kaioken
so you suggest this:
    proc
Wander()
for()
step(src,pick(NORTH,SOUTH,EAST,WEST))
sleep(5)
Old_Man
atom/movable/Move()
icon = 'old_man.dmi'
icon_state = "normal"
New()
..()
Wander()


right?
In response to Adam357
Yeah, that should work, but another thing I overlooked, WTF is the atom/movable/Move line doing there...remove it as well.

Dark Wizard, what's the point of posting a slightly different version of an already posted proc? Especially when it's worse and needlessly adds a list variable to every atom/movable.
In response to Adam357
Kaioken has some idea of what he's doing, but that code won't work. I'm surprised it compiles.

mob/npc //This type path can be the ancestor of all NPCs in the game.
var/delay=10 //By default, NPCs will wait 10 ticks (approx 1 second) between each step. Change delay for individual NPCs to change that
proc
Wander() //All NPCs should have the Wander() proc
while(src) // The line for() shouldn't do anything, as far as I'm aware. while(src) will keep looping while the mob exists.
step(src,pick(NORTH,SOUTH,EAST,WEST)) //This line is fine
sleep(delay) //This way, we can have a variable delay with different NPCs
New()
..() //Always a good idea to call the parent proc
spawn() Wander() //Call Wander(), make sure it's in a different call stack. Always good to make sure New() returns
Old_Man //Defines an Old Man NPC
icon = 'old_man.dmi'
icon_state = "normal"
Page: 1 2