ID:269741
 
usr.maxpowerlevel += rand(1,5000)
usr << "Your Powerlevel Went Up Loads!"
sleep (100)

is there a way so this reapeats without me re writting the code 100000000 times ?
JRR-Zero wrote:
usr.maxpowerlevel += rand(1,5000)
> usr << "Your Powerlevel Went Up Loads!"
> sleep (100)

is there a way so this reapeats without me re writting the code 100000000 times ?

Yes. Use a simple loop like while() or for().

Lummox JR
Your best bet is a while() or for() statement.

Here's a simple example of how you'd do a while().
mob
verb
RepeatMe()
while(1) // This will always be true, since 1 is always 1.
sleep(20) // Two tick delay
src << "Command repeated."


Or you can use a variable so it doesn't loop forever:
mob
verb
RepeatMe()
var/repeat_num = input("Repeat how many times?")as num
while(repeat_num) // Whie the variable is non-null
sleep(20)
src << "Command repeated."
repeat_num-- // Make sure you remove one from the variable or it'll continue on.


for() loops aren't really required in place of while() in most cases, but in the case of the second example a for() would be better since you can include the variable addition/subtraction without having to change the contents of the loop.
In response to Lummox JR
sorry 2 send needy but plz can u write the code ot for me i tried the for()& while()but i was getting
invalid expression


thanks
In response to Nadrew
ahhh thanks again Nadrew
In response to JRR-Zero
ahhhhh nadrew lol i used ur code and now im more confused before lol
on my first code
            usr.maxpowerlevel += rand(1,5000)
usr << "Your Powerlevel Went Up Loads!"
sleep (100)
where willthe while() go ????
In response to JRR-Zero
JRR-Zero wrote:
ahhhhh nadrew lol i used ur code and now im more confused before lol
on my first code
            usr.maxpowerlevel += rand(1,5000)
> usr << "Your Powerlevel Went Up Loads!"
> sleep (100)
where willthe while() go ????

while(1)
sleep (100)
usr.maxpowerlevel += rand(1,5000)
usr << "Your Powerlevel Went Up Loads!"


And Nadrew, for your repeat_num var, it should have been
as null|num
so they could cancel out. :P
In response to Sinoflife
i done that code just now tried it and when i done it my dream seeker froze and shut down : and maby i missed a bit out that might have been important :
verb/Wear()
usr.overlays+=/obj/Weighted_Suit
usr.maxpowerlevel += rand(1,5000)
usr << "Your Powerlevel Went Up Loads!"
sleep (100)


plz help lol
In response to JRR-Zero
verb/Wear()
usr.overlays+=new/obj/Weighted_Suit
while(1)
sleep(100)
usr.maxpowerlevel+=rand(1,5000)
usr << "Your Powerlevel Went Up Loads!"


You really need to learn how to indent properly.
In response to JRR-Zero
[link] Explained it all.. :-|

O-matic
In response to Sinoflife
its still freezing
In response to JRR-Zero
JRR-Zero wrote:
its still freezing

When you run into problems like this, it's best to post the code as it currently stands so we don't have to guess at which parts you changed.

Based on your posts in this thread and others, I think it's likely bordering on certain that you didn't indent the code correctly, so that the sleep() proc is appearing outside of the while() loop.

You seem to be mixing tabs and spaces in your indentation a lot. I strongly recommend you hit Ctrl+T in Dream Seeker to show tab and space characters.

Lummox JR
In response to Sinoflife
Sinoflife wrote:
And Nadrew, for your repeat_num var, it should have been
as null|num
so they could cancel out. :P


It wasn't optional, so I excluded the cancel button on purpose.
In response to Nadrew
Makes no sense to have it nonoptional, I hate to be stuck on input boxes, unwanting to enter anything.
In response to Sinoflife
Sinoflife wrote:
Makes no sense to have it nonoptional, I hate to be stuck on input boxes, unwanting to enter anything.

Agreed. In most cases it's best to include a cancel choice.

Lummox JR