ID:1887821
 
(See the best response by Ter13.)


I was just hoping to get some advice. Let's say I have an NPC that is following a set of commands.

mob/npc/name
verb
talk()
say something
say something
say something
proc()
say something


In this proc I want there to be a halt and having that halt canceled after some action has been taken such as a mob variable changing value. I tried sleep(X) but i'm having trouble deleting the proc() so its sleep(0) and it can move on to the next line. tips or advice?
Best response
You can just have a blocking loop like so:

mob
var/tmp
blocking
proc
WaitForSomething()
blocking = 1
while(blocking)
sleep(TICK_LAG)


The WaitForSomething() proc will not return until blocking is no longer true, thus preventing further action. It will return the minute you change the blocking value.

Quick note: TICK_LAG isn't a real value unless you define it. TICK_LAG should be set to 10/fps.
mob
var
blocking
proc
WaitForSomething()
blocking = 1
while(blocking)
sleep(100)



mob
verb
unblock()
usr.blocking = 0

I did this verb to test the function, it doesn't seem to be continuing the action after I set the blocking value. any Idea why this might be?
Put your code inside of DM tags:

<DM>
code goes here
</DM>

I did this verb to test the function, it doesn't seem to be continuing the action

Well, 100 is 10 seconds. You probably don't want to be sleeping that long. You want to sleep for a single tick, which is determined by 10/fps.

Also, I'm pretty positive that you are calling WaitForSomething on the wrong object.
Yep, that's because you aren't calling WaitForSomething() on the right mob.

You should be calling usr.WaitForSomething().

no matter what I set sleep() to, it wont change once I change the value

Your sleep value should be 10/fps and nothing else in WaitForSomething(). There's no experimentation. There's no need to change the value, it's exactly 10/fps.
In response to Ter13
Ter13 wrote:
> mob
> var
> blocking
> proc
> WaitForSomething()
> blocking = 1
> while(blocking)
> sleep(TICK_LAG)
>


Hummm I strongly advise u to make the blocking var a temporary var like this mob/var/tmp/blocking
Hummm I strongly advise u to make the blocking var a temporary var like this mob/var/tmp/blocking

That's fantastic advice. Also, there are issues that will be caused by someone logging out while a blocking function is happening, but those are beyond the scope of this post.
Its not easy being a noob. Thanks Ter13 you were patient and great! Hope to speak again in future posts
Its not easy being a noob. Thanks Ter13 you were patient and great! Hope to speak again in future posts

Heh. Don't worry about it. We all start somewhere. You have to make the mistakes to understand why they were mistakes. I'm always happy to help.