AboutLoops

@LOOP is a very nice feature, but also very very dangerous! Because of this I have decided to make @LOOP an advanced mode feature and to have it turned off by default. This means you cannot use @LOOP unless advanced mode it turned on.

You must read this entire page to understand how to turn on loops.

I will not just tell you how to turn it on. Only advanced users who have an understanding of plugins and VariableTriggers proper scripting rules should even think of using @LOOP.

A word about loops. You must use extream caution. Inexperianced scriptors and experianced ones may find that they unintentionaly crashed their server. Although I have set a 1000 count limit per loop it is still very easy to let things get out of control. One very important thing to remember, NEVER do a recursive @CALL inside a @LOOP block. This means do not @CALL a script that calls itself or call a script that then calls this script. Combining LOOP with recursive @CALLs will exponentially increase the number of times the loop is called.

@LOOP will do exactly what it is told to do. So think about what you are trying to do before you create it and remember that if you do to much to quick you will cause Exceptions on your server. These Exceptions can lead to a crash.

@LOOP is an AdvancedMode feature that will be turned off by default.

Here is a sample

  looptest:
    Script:
    - '@IF b $<playername>.test44 = true'
    - '    @SETBOOL $<playername>.test44 false'
    - '    @LOOP 4'
    - '        @PLAYER true loop 4 times'
    - '        @IF si <playername> = <playername>'
    - '            @LOOP 2'
    - '                @PLAYER inner loop 2 times'
    - '            @ENDLOOP'
    - '        @ENDIF'
    - '    @ENDLOOP'
    - '@ELSE'
    - '    @SETBOOL $<playername>.test44 true'
    - '    @LOOP 3'
    - '        @PLAYER false 3 times'
    - '    @ENDLOOP'
    - '@ENDIF'

If you use any BLOCK seting commands, do not change more than a couple dozen at a time.

This would make a cube 10x10x10
Thats 1000 blocks your trying to change all at once. Way too many!!!

  blocks:
    Script:
    - '@SETINT $pos.x -5'
    - '@LOOP 10'
    - '    @SETINT $pos.y 10'
    - '    @LOOP 10'
    - '        @SETINT $pos.z -5'
    - '        @LOOP 10'
    - '            @SETBLOCK 35:<random0to:6> <relativeloc:<playerloc>:$pos.x,$pos.y,$pos.z>'
    - '            @ADDINT $pos.z 1'
    - '        @ENDLOOP'
    - '        @ADDINT $pos.y 1'
    - '    @ENDLOOP'
    - '    @ADDINT $pos.x 1'
    - '@ENDLOOP'

It may not crash your server this time or that time but it very well may at some point and at the very least you may end up with advers side effects. That is why I optioned to make it an advanced feature.

If you need to manipulate a large number of blocks in a script you can use @CMDOP with worldedit commands inside your script. Worldedit is designed for this purpose. VariableTriggers is not desined to handle a lot of blocks all at once.

The command @LOOP 1000 will repeat all the script lines after it and up to the matching @ENDLOOP 1000 times. If you have Heavy script commands such as @SETBLOCK, @TOGGLEBLOCK, @ENTITY, @SOUND, @GETENTITYCOUNT, @DROPITEM or any visual effect commands inside this large loop you risk a server crash or at least unwanted advers side effects. Take the @SOUND, it plays a sound and if you are using it inside a loop it gets called 1000 time very fast almost all at once depending on how many other lines of script are inside the loop with it. If you try telling the server to play that many sounds all at once you will crash. That is why I configured it to be off by default.

If you create a loop to set blocks with the @SETBLOCK or @TOGGLEBLOCK commands, do not try changing more than a couple dozen blocks. You will eventually crash your server if you try to change too many blocks at once. Instead use @CMDOP to use Worldedit commands inside your script to manipulate a large number of blocks. The file for Worledit can be downlaoded from there project page.

You should also keep in mind that some triggers will get activated a lot and at a fast rate. Take for instance EntitySpawn. If you create an EntitySpawn event trigger it is going to activate every time a new entity spawns that includes Zombies, Cows, Pigs, Villagers and all entities and depending on your server settings that may be as much as 20 times a second. So if you set a @LOOP in this script and it is a long loop that does a lot you will see your server start lagging at the very least.

The inportant thing to keep in mind is that whatever you tell the script to do it is going to do it even if the server cant handle the volume of commands you give. This is true even if it will cause a crash.

Setting a @COOLDOWN in the beginning of a script that has a long loop or a lot of nested loops so it can only be activated one at a time will help protect you with large loops but not guarantee you protection it will only help the script not get activated by another player while it is already running.

What it comes down to is this; if you do not already understand some kind of program language and propper logic structure you shoult NOT use @LOOP's. I configured it to have a hard limmit so you don't create an infanite loop but it's more impotant that you don't do to many loops with certain commands.

For a hint about turning on loops you should re read this page but pay attention to the green words in this document. If you get the hints and still do not know how to do it then you don't need to use loops.

And remember, I have warned you repeatedly on the dangers of using @LOOP inproperly in your scripts. If you crash your server or get adverse side effects don't blame me or VariableTriggers. Blame yourself for not listening to my warnings or your lack of propper usage of @LOOP.

If you have not read this entire page then you do not know how to turn on @LOOPS. If you do figure out how, do NOT post to anyone how to do it. They need to read this for themselves. Thanks.

Also, the password is drowssap.