basicly, it runs a timer that triggers the E2 every 0.2seconds, if the button is on (toggle), the Time ads 1 to itself, if the time is >3 it will make the light red, else blue
Alright I wrote an expression today (I am kind of new to it), and It was meant to flash lights like police light. I realize that I had to have the lights set to 255. But my friend changed my code so that I don't need a timer gate. But, can someone explain this code for me? I really dont understand how the interval command corresponds to the Time variable and what += means.
Here is the code:
@name Lights
@inputs Toggle
@outputs Red Blue Reset Time
@persist Variable I
#Timer
interval(200)
if (Toggle==1) {Time+=1}
if (Time > 3) {Time=0}
if (Toggle==0) {Time=0}
if(Time > 1){Red=255,Blue=0}
if(Time < 2){Red=0,Blue=255}
if (Toggle==0) {Red=0,Blue=0}
basicly, it runs a timer that triggers the E2 every 0.2seconds, if the button is on (toggle), the Time ads 1 to itself, if the time is >3 it will make the light red, else blue
New server IP: 89.238.160.17:27018
Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
Unsmart: I doubt the intelligence of some people.
Drunkie: Nobody could have said that any better than Unsmart.
Unsmart: Solece, I totally did your mom yesterday
Solece: Who hasnt
Divran: there are more retarded people than there are clever people in this world
Hi, im going to try to explain this the best i can.
1.Interval means how much time there is before it gets checked again,
interval(1000) is equal to 1 second. Its kinda like a timer within the E2
2. += means not equal to,
example if(Button += 3) {Thrust = 1} or more advanced
if(Button += 3)
{
CS:writeString("The button is not equal to three.",0,1,999,0,0)
}
If you want to use that code than you would need to learn console screens.
I hope this helps.![]()
Gawd, please read the wiki before answering a question like this if you aint sure.
+= means it adds by the number.
so if you do:
Cake += 2
Cake += 10
Cake will then add 2 to itself, then add 10 to itself, outputting 12.
Not equal to is !=
Get out. Seriously, do it.
Oh that's right I forgot, sorry for the bad info, its one am.
this is the sort of thing that is going to lag a bit on the servers but using interval is the fastest way, it will just flash the lights from red to blue thought the last 2 lines before the last one is really bad code it will work but there are quicker ways then using binary logic.
that will make better senceCode:@name Lights @inputs Toggle @outputs Red Blue Reset Time @persist Variable I #Timer interval(200) if (Toggle==1) {Time+=1} if (Time > 3) {Time=0} if (Toggle==0) {Time=0} if(Time == 1){Red=255,Blue=0} if(Time == 2){Red=0,Blue=255} if (Toggle==0) {Red=0,Blue=0}
Last edited by Vbitz; 10-19-2009 at 11:58 PM. Reason: code bug
Questions, Comments and Concerns about any of
my posts can be directed to my website which is at
http://vbitz.wordpress.com on the comments post
SVN Tutorial
My SVN:Get dropbox and get 250 MB extra space: DropboxCode:http://divranspack.googlecode.com/svn/trunk/%20divranspack/
well where i am meens i get about 200 or so latincy on servers and i am a programmer so every little improvement is good
Questions, Comments and Concerns about any of
my posts can be directed to my website which is at
http://vbitz.wordpress.com on the comments post
Yes, of course. Removing OPS is always good.
So I'll optimize the code even more. Hold on a second...
Code:@name Lights @inputs On @outputs Red Blue @persist Time interval(On*200) #This will make it use 0 ops when off if (!On | Time >= 2) {Time = 0} #Reset Time when bigger than 2, or if off Time++ #Add time Red = (Time == 1 & On) * 255 #Make red blink Blue = (Time == 2 & On) * 255 #Make blue blink
Last edited by Divran; 10-20-2009 at 01:27 AM.
SVN Tutorial
My SVN:Get dropbox and get 250 MB extra space: DropboxCode:http://divranspack.googlecode.com/svn/trunk/%20divranspack/
sooo. optimization is basicle removing as many if, while, for etc as possible?
so
if (On==1)
{
if (Me==1)
{
code
}
}
if I optimize it, it should be:
if (On & Me)
{
code
}
is that a correct assumption?
Bookmarks