Author Topic: Wrench Events Tutorial (learn some stuff here)  (Read 19755 times)

Replace the "i have no clue what this does" one with this, I think this is what he was getting at.

 How to make a wrench event counter

 - Make 2 print bricks beside each other, so you have a 2 number counter. Name the one on the left.
 - For the first brick, make two events.
    - onActivate -> self -> incrementPrintCount -> 1
    - onPrintCountOverflow -> namedbrick (left brick's name) -> incrementPrintCount -> 1
 - Click on the right brick. When you click on it, the number increases. When it goes past 9, the left number increases.

no.. i think i already know how to do that

Yeah but other people might not

Mr. Wrench Events Tutorial >_>

HAH! I TOLD YOU! HE WANTS TO LEARN EVENTS, NOT FOR OTHERS! HAH!

Needs moar keypad tutorial.

I dont get the point of this one

Spawn a two print bricks and put one print as 0 and the other as 9 and name the 9 something (ex:count) and now spawn a brick and do this with it

onActivate>NAMED BRICK>incrinimate
You can count and when it goes over nine make it do something.

HAH! I TOLD YOU! HE WANTS TO LEARN EVENTS, NOT FOR OTHERS! HAH!

accourse i would like to learn something new about events? i know how to use them and i understand it all exept relays (currently messin with)

Thank you really much for that tutorial.

A simple tripple rocket launcher using relays, easily enhancable:


Events:
 - Brick1


 - Brick2


 - BrickAboveBrick2


 - The 3rd Brick


 - Only Brick1 and Brick2 need to be given a name, the other ones work without one,
this is one of the benefits of using relays.
 - Brick1 is the Button , Brick2 and the Bricks above are the cannons.
 - Brick1 will be disabled for a short amount of time until all three cannons have fired (a bit longer).
(This prevents spam)

hope this explains the Relay stuff a bit, it's also possible to use the other Self -> FireRelayWest/North/East/South/Down/Up , you just have to find out in what direction the brick you want to trigger is positioned to the one that fires the relay, also, they have to be directly beneath each other for that, no spaces allowed.

---- a bit more advanced is looping, let's make a simple brick that is toggleable and changes color in a rythm of 1 second.


now, here is how it works:
 - When you press the button the first event fires the relay onto the brick, triggering all enabled onRelay events.
 - Also, the button press toggles the event0 off and the event2 on.
 - event2 is the most important one for this, it is the main point for loops, as it will use the fireRelay function every 1000ms (1 sec) and will trigger itself and the other onRelays again and again.
 - event3 and 4 set the different colors, now, the trick is, to use an onRelay to make one of the disabled and the other one enabled, it's just another toggleswitch.
 - when you press the button again, only event1 will be triggered switching event2 off (loop ends) and event0 on (you can initiate the loop again).

hope this helps some of you.

one of the good things here is the fact that the event query list is very short, you can use relay loops so you don't have to use delays so much, causing the event query list to get too big.
Also, you shouldn't edit this brick while the loop is active.
« Last Edit: August 19, 2008, 11:58:02 AM by Zerosan »

zerosan, can you shorten down what the does..?

The first one is a 3 slot turret shooting rockets, one after another, activated by a button, that you can expand quite easy. (Switches, Relays)

The second one is a normal brick that changes color every second, that you can toggle on and off. (Loops, Relays, toggleEvents)

The first one is a 3 slot turret shooting rockets, one after another, activated by a button, that you can expand quite easy. (Switches, Relays)

The second one is a normal brick that changes color every second, that you can toggle on and off. (Loops, Relays, toggleEvents)


okay... i like and understand how you made it shoot rockets one after another, but the color one..?

Yeah, that one is a bit harder, or better, tricky :)

You have to look at it in a different way.

The first part is Event0 and Event2. (Both activated in this case).
When Event0 is started it issues the fireRelay function onto itself, causing Event2 to be executed.
Event2 has a 1000ms delay, then it also uses the fireRelay onto itself, causing itself to be executed again.
and again. and again. and again.

That's a loop.

Now, the next step, I want to prevent the loop from beeing started while it is already running (spam protection) and also, I want it be stoppable, still, using the same brick.
This is where Event1 comes in, it toggles the event status of the events with the id's given in the textfield, I put in Event0 and Event2, as only one should be active at a time, this is why the initial value of Event2 has to be inactive (the event has to be disabled at the beginning) and Event0 has to be enabled.
When you now press the brick, Event0 will start the loop by firing the relay and Event1 will enable Event2 making the loop possible.

Now we have a loop that you can toggle.

Now I want something to happen everytime the loop goes through one cycle, well, fortunaly, we have the onRelay, that we used in Event2, we just use it for both colors, so I set Event3 and Event4 to a setColor, and apply the toggleEvent function both of them, leaving one of them enabled, the other one disabled, the toggleEvent function also is triggered by the onRelay, causing Event3 and 4 to be switched every second.

That's it, it basically has 3 steps.

this is a nice tutorial but can we have a someone say how to make a self countdown? i tried doing it with relays but it failed.

I'm a bit to lazy right now to do a proper tutorial for this, but I will make a quick one now:

Let's make it simple first, how to make a loop is clear right?
On every cycle of the loop you need to use fireRelay on the first PrintBrick (the one with the smallest unit)

the events on the printBrick are like this:

0: 0ms - OnRelay - Self - decrementPrintCount - 1
0: 0ms - OnPrintCountUnderflow - Self - FireRelayWestNorthEastWest

important for this is, you have to set the proper fireRelay, the direction, so just find out in what direction the next printBrick is positioned.
you can just use the same events for every next digit then, expanding the counter as much as you like.

and on the last one you just use onprintCountUnderflow to let something happen.

this is a nice tutorial but can we have a someone say how to make a self countdown? i tried doing it with relays but it failed.

try

Onactivate>self>incrimanatecount

onRelay>self>incrimanatecount

i did this out of mind, i never tried it ingame