if(usr.stamina <= 1)
sleep(10)
usr.stamina+=rand(5,25)
else
usr<<"You have plenty of stamina."
How do i get :
sleep(10)
usr.stamina+=rand(5,25)
to loop or keep going?
ID:167170
Apr 18 2006, 6:59 pm
|
|
Apr 18 2006, 7:11 pm
|
|
Look up Spawn in the reference
|
In response to A.T.H.K
|
|
I tried spawn while(10) and all it did was freeze my game (test) This is the code im tring to get to repeat itself till its reaches its if barrier
mob verb Rest() set category = "Train" if(usr.stamina <= 1) spawn while(10) usr.stamina+=rand(5,25) else usr<<"You have plenty of stamina." |
In response to IceBlue
|
|
Try this:
mob Notice also how I changed usr to src. I suggest that for all other verbs, and other appropriate places (I am not very good at explaining what the "appropriate" places are myself, but there are plenty of people on BYOND that can help with that.) you change them as well. Or as Lummox would say: "No put usr in proc UNGH" or something along those lines >.> |
In response to Satans Spawn
|
|
"No put usr in proc UNGH"
Its a verb not a proc but still yea no usr |
In response to A.T.H.K
|
|
Technically I think a verb is just a proc under a different name that has the capability of being accessed without being called by another proc... but either way, you are right, it doesn't really matter either way, the important thing is that Lummox says proc so I didn't want to change it to Don't put usr in verb UNGH... cause after many many times of seeing Don't put usr in proc UNGH... it just looks wrong...
|
In response to Satans Spawn
|
|
Verbs are procs, yes, but that does not mean they are exactly like procs. In most all situations in verbs usr will be safe to use. usr > src in this situation.
One reason why you would want usr, is because if you have, let's say, an obj/verb, the src would be the obj and not the player calling the verb. |
In response to Artekia
|
|
*hangs his head in shame*
Thanks for pointing that out to me :D |
In response to IceBlue
|
|
mob There are two main things wrong with this function, and they both center around the spawned while() statement. while() keeps going as long as it's argument is true. 10 is always true, therefore your while statement will always run. Spawning it off of the main function doesn't do anything here. What you are probably looking for is something more like this: mob |
In response to Artekia
|
|
Thats the main reason I use usr and not src... alot of my code revolves around the usr in procs and verbs
Thanks. Iceblue |
In response to IceBlue
|
|
Let me say that there should be no dogma war between usr and src. They have two distinct meanings and, as long as you're aware of what the distinctions are and you understand when one should be used rather than the other, you don't really need to think about it. I've written a lot of BYOND code, and I rarely use usr. Maybe I'm writing differently than all of you are, but src makes more sense in most cases.
|
In response to Satans Spawn
|
|
mob/verb/Rest() Totally untested but should work. |
In response to Chrisman767
|
|
The goto use is bad programming practice. There are few places where goto is needed. It would probably work better being written as:
mob/verb/Rest() I saw no need from break restloop, or identation after restloop. |
In response to Popisfizzy
|
|
Both of your examples will cause various problems in game.
The first, as you've noted, Popisfizzy, is the lack of any sort of waiting. Without a spawn() or sleep() statement, the looping is pointless; to the user, it'll just look like his stamina was set to max the moment he used the command. In fact, it will be worse than that, because it isn't limiting the amount to max_stamina. It's adding a random amount, which may result in stamina being greater than max_stamina. The biggest problem occurs when we do add some form of time distribution. If you put in a call to sleep(), thinking that that will make the character wait, what is to stop them from calling Rest() again? If the user uses the command five times, they'll have five recovery loops running, and will recover five times faster. Rest() needs to check if the character is already resting. This is accomplished, in my example, by separating what the user can control from what the game is doing. I've created an interface by which the player interacts with his character. I've put the real work in a proc that the user has no control over, and put the options that I want the player to have into a verb. |