• e2 help
    6 replies, posted
I was wondering if someone could help me with some e2 scripting. I want to make it so that a screen will randomly generate numbers for a set period of time. The script so far is as follows: @name example @inputs Button @outputs Screen if (Button=1) {Screen=round(random(9))}
[code] @name Example @inputs Button @outputs Screen # This sets the time limit before the Expression refreshes itself again. 1000 = 1 second. This is ALSO how long it will take for it to generate a new number, so for now, it will generate a new number once every second. interval(1000) # If the Button is being pressed, generate a random integer between 0 and 9. if(Button == 1 ) {Screen = randint(9)} [/code] What it will do is: as long as the button is being pressed, the Expression will output a random number, 0-9. Pointers: * When using equals signs to compare values, use "==", not "=". In accordance, use "=" when setting values. * Instead of using round(random(Variable)), use randint(Variable). [url=http://wiki.garrysmod.com/?title=Wire_Expression2#Features]* Read this if you haven't.[/url] Also: Look at what section you're posting in next time. E2 threads would go in [url=http://www.facepunch.com/forumdisplay.php?f=16]Help & Support[/url]. This is the garrysmod.org section.
what if I want to make it do that for 5 seconds without a toggle on the button?
[code] @name Example @inputs Button @outputs Screen @persist Generate # This sets the time limit before the Expression refreshes itself again. 1000 = 1 second. This is ALSO how long it will take for it to generate a new number, so for now, it will generate a new number once every second. interval(1000) if(Button & ~Button ) {Generate = 1, stoptimer("Stop"), timer("Stop",5000)} if(Generate == 1 ) {Screen = randint(9)} if(clk("Stop") ) {Generate = 0} [/code]
Slight tidy up. I can't stand messy code or 'retarded' styles. [i]Retarded to be taken lightly, and does not imply any kind of mental illness or defect.[/i] [code] @name Example @inputs Button @outputs Screen @persist Generate # This sets the time limit before the Expression refreshes itself again. 1000 = 1 second. This is ALSO how long it will take for it to generate a new number, so for now, it will generate a new number once every second. interval(1000) if(Button & ~Button) { Generate = 1 timer("Stop",5000) } if(Generate) {Screen = randint(9)} if(clk("Stop")) {Generate = 0} [/code]
[QUOTE=whosdr;23647367]Slight tidy up. I can't stand messy code or 'retarded' styles. [i]Retarded to be taken lightly, and does not imply any kind of mental illness or defect.[/i] [code] @name Example @inputs Button @outputs Screen @persist Generate # This sets the time limit before the Expression refreshes itself again. 1000 = 1 second. This is ALSO how long it will take for it to generate a new number, so for now, it will generate a new number once every second. interval(1000) if(Button & ~Button) { Generate = 1 timer("Stop",5000) } if(Generate) {Screen = randint(9)} if(clk("Stop")) {Generate = 0} [/code][/QUOTE] I like that approach. being an asshole and a nice guy at the same time. Its like helping someone fix their car on the freeway while their wife is pregnant in the car and when they take off, theres a rotten fish under the hood. funny but mean at the same time and not hurting anything.
Thanks a lot! I'll be sure to include all of you that helped if I make this into an addon.
Sorry, you need to Log In to post a reply to this thread.