ID:158667
 
Okay, for my sparring system, I want someone to be able to summon a puppet, and get a verb called "Spar", that much I can do. But what my problem is, I want the verb to keep repeating the Levelup() proc, until either the player presses the verb again, or he runs out of stamina. How would I do this?

My "watch" verb, is a verb that would allow the player, once pressed, view a specific area. Not just a chord, but kind of like a section of a map, how would I do this?

Thanks
1) You want a loop. Just for() [with no arguments] is a good infinite loop if needed.

2) Change the player's eye location (eye = locate...)
In response to GhostAnime
I'm sorry, but could you go in a little more detail with both? Specifically the second one?
In response to Madhedghog34343
1)
for()   //  one form of an infinte loop
src << "Infinite loop!"
sleep(10) // outputs above message every second


2)
X's client eye = locate(coordinates)
In response to GhostAnime
GhostAnime wrote:
2)
X's client eye = locate(coordinates)


Just to add, you also will want to set the client's perspective to EYE_PERSPECTIVE, as the player will get a black screen if it is too far away from the client's mob.
In response to GhostAnime
I haven't really attempted 2 yet, but I got 1 working partially, here's what I got:
                if(!usr.doing&&usr.health >= 1)
if(usr.training == 0)
usr.training = 1
usr<<"You start training with your puppet."
for()
usr.Levelup()
sleep(10)
if(usr.training == 1)
usr.training = 0
usr<<"You stop training with your puppet."

Obviously, the proc continues when he uses the verb the second time. So, how would I make it so the proc stops?

And on the second question, when inputing the choords, do I enter just on set (EX: 20,20,1), or something else?
In response to Madhedghog34343
Anyone?
In response to Madhedghog34343
Madhedghog34343 wrote:
I haven't really attempted 2 yet, but I got 1 working partially, here's what I got:
>               if(!usr.doing&&usr.health >= 1)
> if(usr.training == 0)
> usr.training = 1
> usr<<"You start training with your puppet."
> for()
> usr.Levelup()
> sleep(10)
> if(usr.training == 1)
> usr.training = 0
> usr<<"You stop training with your puppet."
>

Obviously, the proc continues when he uses the verb the second time. So, how would I make it so the proc stops?

And on the second question, when inputing the choords, do I enter just on set (EX: 20,20,1), or something else?


He wont stop training
try this
if(usr.health<1&&!usr.doing)
if(usr.training==0)
usr.training=1
usr<<"You start training with your puppet."
for()
if(usr.traing==1||usr.health<=1)
break //cancels loop
usr.Levelup()
usr.health--//minus health
sleep(10)
if(usr.training == 1)
usr.training = 0
usr<<"You stop training with your puppet."
In response to Madhedghog34343
                if(!usr.doing&&usr.health >= 1)
if(usr.training == 0)
usr.training = 1
usr<<"You start training with your puppet."
for()
usr.Levelup()
sleep(10)
if(usr.training == 1)
usr.training = 0
usr<<"You stop training with your puppet."


Just some questions and some advice...

1) Why do you need this infinite loop? By the looks of it, you DO want it to stop, and want to fill in the required areas for for() (check advice below).

Advice (yeah, ran out of questions =/):

1) instead of if(usr.training == 1) use if(usr.training). I don't see why you're checking for an individual value here, when above you use boolean methods.

2) Using for() (from the reference):

for loop proc
See also:
break proc
continue proc
do proc
for list proc
while proc
Format:
for(Init, Test, Inc) Statement
First execute Init. Then if Test is true (non-zero), execute Statement. After this execute Inc. Continue checking Test, doing Statement, and performing Inc until Test turns out to be false (zero).

Statement may be a code block or a single statement. Semicolons may be substituted for commas inside the parentheses as a convenience to C/C++ programmers.

Init and Inc may be omitted. If Test is omitted, the loop will continue forever (unless a break, goto, or return instruction is used to get out of the loop).

Example:
var/i
for(i=0, i<3, i++)
world << i

This outputs:

0
1
2

Using this information, and some assuming, I think you want to use this (explanation included):

if(!usr.doing)          //If usr.doing is false...
if(!usr.training) //And usr.training is false...
usr.training = 1 //Make usr.training true.
//Take note that the line break in for() is simply used to improve
//readability, it doesn't do anything else.
for(usr<<"You start training with your puppet.", //Tell usr what they're doing.
usr.training&&usr.health>=1, //Check that they're training and healthy.
usr.Levelup()) sleep(10) //Level them up before sleeping for ten ticks.
else if(usr.training) //However, if usr.training is true
usr.training = 0 //Make it false, and stop them from training.
usr<<"You stop training with your puppet." //Give them the message.
In response to Demon_F0rce
//I imagine this is a mob/verb, so why are you using usr?
if(!src.doing)
if(!src.training)
src.training=1
while(src.training) //aslong as your training
src.Levelup()
sleep(10)
//Unless you want them to level up forever
//just set the src's training to 0.
else //it isn't false, they ARE training.
src.training=0 //stop them from training


Demon, that was some bad stuff. >_>; That for() loop doesn't even make sense.
In response to Vic Rattlehead
I'm curious - what do you mean it didn't make sense?

Also: usr is fine in verbs, as usr is the person who pushed the verb. You're thinking of procs a bit, I daresay.
In response to Demon_F0rce
                    for(usr<<"You start training with your puppet.",usr.training&&usr.health>=1,usr.Levelup())

Really, do I have to explain the flaw in that?
And two, while it may be fine... why use usr if you don't have to?
In response to Vic Rattlehead
I see no flaw in that; please explain.

Second, why use src when you know usr will return exactly what you want/need?
In response to Demon_F0rce
Your sending a message INSIDE the for() loop? Does that even compile? Two, why NOT use src when there's no reason not to? If both do the same thing, just go with src? If you get too used to typing usr for everything because "theres no difference", you'll make errors later on.
In response to Vic Rattlehead
1. What's wrong with sending a message inside the for() loop? The message is what gets the for() loop started. There's nothing wrong with that.

2. It would be better practice, in my opinion, to use usr for verbs when wanting to use the client pushing the verb, and src for procs, when using the atom calling the proc. I'm sure you know why the src for procs, but why usr for verbs? In this example:

obj/Pie/verb/Eat()
usr<<"You ate a pie."


src is equal to the Pie, not the person eating the pie. Therefore, it is a better idea to practice using usr for verbs.
In response to Demon_F0rce
I'm not even going to bother explaining to you why that for() loop was the worst piece of programming not including goto.

Two, /obj/verb != /mob/verb, pretty sure you knew that though.
In response to Vic Rattlehead
1) By not bothering to explain it to me, you are ensuring that I do not learn, since I am failing to see nothing wrong with it, which ensures that I continue to spread said "bad programming practices". Just so you know =P.

2) I do know that, however it's good practice since usr is equal to the person using the verb. For example, a new programmer might not know that /obj/verb != /mob/verb. Until they do know this, it is a good idea that they start with some basic knowledge:

Using usr in procs will not always cause what you want to happen, using src is safe.

Likewise for verbs, however it is safer to use usr than src in this case, not the other way round.
In response to Demon_F0rce
Okay, thanks for the help, here's my final code:
                if(!usr.doing&&usr.health >= 1)
if(usr.training == 0)
usr.training = 1
usr<<"You start training with your puppet."
for()
usr.Levelup()
usr.health -= 1
sleep(10)
if(usr.training == 0)
break
if(usr.training == 1)
usr.training = 0
usr<<"You stop training with your puppet."


I'm still not exactly sure how to do number two considering I've never attempted it before nore have I seen it...
In response to Madhedghog34343
That's rather poor code, right there, aside from not using while(usr.training) instead of the silly for() and if(usr.training) break. The thing that so many people seem to ignore is the case where the event is spammed. So, for example, if you were to click the button three times, you'd toggle training on and off and on, and two loops would be running (because they only check the training variable once per second).

The best way to prevent this is for the training variable to store additional data, relating to either when or how many times you've clicked the button. In the verb, it would store the value of training when it started, and the loop would break if that value changes. So, we would do something like this:

mob
var/poking = 0
verb/poke()
if(!poking)
//we add 1 to world.time in the super-unlikely case that we call this the moment the world starts
poking = world.time + 1
var/mypoking = poking
sleep(10)
while(mypoking == poking)
view() << "POKE"
sleep(10)
else
poking = 0


This way, two loops cannot be running at the same time, unless you called poke() three times within the same tick... which isn't going to happen from player input. Though, if it IS an issue, you can instead simply count the number of calls rather than world.time (but, inconveniently, you can no longer use if(poking), and must use if(poking%2), as an odd number of calls means it should be on):

mob
var/poking = 0
verb/poke()
poking++
if(poking%2)
var/mypoking = poking
sleep(10)
while(mypoking == poking)
view() << "POKE"
sleep(10)