Log in

View Full Version : repeat "x"??



forac
10-28-2012, 06:32 PM
Hey, so I wrote a script and it has to repeat one action 46 times... How can I tell it to repeat 46 times?? I tried at the end of every 1 action for it to add 1 to x then when x = 46 to go to next action. Can anyone help? i need asap

Mr[S]
10-28-2012, 06:33 PM
Add in a master loop?

forac
10-28-2012, 06:35 PM
How do i do that lol, yesterday was literally the first time i looked at this type of scripting.

anonymity
10-28-2012, 06:44 PM
Here is a basic loop.
Program New;
var
x : integer; // the variable you will increment
Begin
x := 0; // set the variable equal to something
repeat // start the repeat/loop
writeln('x = ' + inttostr(x)); // do something
x := x+1; // increment the variable, (variable = variable + 1)
until(x = 46); // end of loop, when x = 46
End.


// basically, in C
// for (int x = 0; x != 46; x++){
// do stuff
// }


Might I suggest you take a look at some of the brilliant scripting tutorials : http://villavu.com/forum/forumdisplay.php?f=95

Rezozo
10-28-2012, 06:48 PM
for (x:=1 to 46 do)
(Bla bla bla?);

forac
10-28-2012, 06:50 PM
Here is a basic loop.
Program New;
var
x : integer; // the variable you will increment
Begin
x := 0; // set the variable equal to something
repeat // start the repeat/loop
writeln('x = ' + inttostr(x)); // do something
x := x+1; // increment the variable, (variable = variable + 1)
until(x = 46); // end of loop, when x = 46
End.


// basically, in C
// for (int x = 0; x != 46; x++){
// do stuff
// }


Might I suggest you take a look at some of the brilliant scripting tutorials : http://villavu.com/forum/forumdisplay.php?f=95
Will check those tuts out thanks man.


for (x:=1 to 46 do)
(Bla bla bla?);
would this work? seems really simple... I'll give it a try :P ty

anonymity
10-28-2012, 07:10 PM
Yes, that should work. Take the parenthesis () off the for.
Program New;
var
x : integer; // the variable you will increment
Begin
for x:=1 to 46 do // the loop control
writeln('x = ' + inttostr(x)); // do something
End.

h4x0rdafuq
10-28-2012, 09:57 PM
Another way would be to use Inc(I);

Program New;
var
I : integer; // the variable you will increment
Begin
if not (I = 46) then
inc(I); //adds 1 every time
writeln('I = ' + inttostr(I)); // do something
end else
writeln('done');
End.
This exact example probably doesn't work but something along the lines because i use the method inc()

Tickyy
10-28-2012, 10:31 PM
Another way would be to use Inc(I);

Program New;
var
I : integer; // the variable you will increment
Begin
if not (I = 46) then
inc(I); //adds 1 every time
writeln('I = ' + inttostr(I)); // do something
end else
writeln('done');
End.
This exact example probably doesn't work but something along the lines because i use the method inc()

that definitively isn't going to work, here's some help:

Program New;
var
I : integer; // the variable you will increment
while not (I => 46) do
begin
inc(I); //adds 1 every time
writeln('I = ' + inttostr(I)); // do something
end;
writeln('done');
End.

Runehack123
10-29-2012, 01:02 AM
Doing a simple for loop or increasing an integer value will NOT repeat an action X times.
It will simply run through that loop in a couple of milliseconds X times.

I have started a similar thread like this a week ago being new and all.
So hey, I get how you're feeling right now. My first piece of advice would be not to get stuck on something like this - get started with reading tutorials and don't start trying to do things you can't do.
For instance, repeating an action X times might seem very basic, but it's really not. What these people are telling you is how to run through a loop X times, which in my opinion isn't looking at the whole picture - no offence.

What I would do:
Create a function, which has a boolean result along with some waits and timers. It's complex, it's tricky for beginners like you and me and you'll need to read into it if you want to know how. Once you did that, you can incorporate it in your main loop using those methods mentioned above.
The hardest thing will probably be finding a way to get your result to only turn out 'True' when it's done whatever it is that you're trying to get it to do.

Hoping I helped a bit :)