Blockland Forums > Modification Help
Iban Explains it All
<< < (6/39) > >>
Iban:
trace(1);

trace(0);
to deactivate.
Treynolds416:
Is there a way for the script to check if a certain action has been completed, then do another action?

For example:

--- Code: ---function DoSomething(%var1)
{
for(%i=0;%i<%var1;%i++)
{
ServerCmdSomething(Parameters);
ServerCmdSomethingElse(Parameters);
}
}
--- End code ---
I want it to say "The variable %i is currently (x)" after it has completed the specified actions the specified number of times.

So I would type:

--- Code: ---echo("The variable %i is currently" SPC %i);
--- End code ---

But, where would I put it?


If I put it here...

--- Code: ---function DoSomething(%var1)
{
for(%i=0;%i<%var1;%i++)
{
ServerCmdSomething(Parameters);
ServerCmdSomethingElse(Parameters);
                echo("The variable %i is currently" SPC %i);
}
}
--- End code ---
...it wouldn't work.

If I typed DoSomething(5); into the console with this code, the feedback I would get is

The variable %i is currently 1
The variable %i is currently 2
The variable %i is currently 3
The variable %i is currently 4

So how do I make this so that the feedback would be only, for example, "The variable %i is currently 5"?

Any help is appreciated.
Iban:
I'm having trouble understanding what it is that you want.
If you're doing a for loop and want to know how many times the loop was ran, just do this.


--- Code: ---function doLoop()
{
for(%a = 0; getRandom(0, 50) > 0; %a++) { }
echo("%a = " @ %a);
}
--- End code ---

In this example, the loop will run forever, or until the getRandom() function returns a 0.
After the loop terminates (assuming it ever does), it echos %a. If I wanted to report how many times the for loop actually ran, I can either echo %a + 1 or start the for loop with %a = 1;.
Treynolds416:

--- Quote from: Iban on March 03, 2011, 09:57:32 PM ---I'm having trouble understanding what it is that you want.
If you're doing a for loop and want to know how many times the loop was ran, just do this.

--- End quote ---
I'm asking how to make the echo not actually part of the loop.

So that when the loop ends of its own accord, the action will happen once, only once, and only after the loop terminates.

It isn't necessarily an echo, that's just an example. It could be another function, or a variable statement, or anything, really.
otto-san:
The whole cat/datablock comparison really helped me understand how datablocks work better. :D
Navigation
Message Index
Next page
Previous page

Go to full version