+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Can someone explain this code to me? (Includes Working Police Light Code)

  1. #1
    Wire Noob xDa Bidnessx's Avatar
    Join Date
    Oct 2009
    Posts
    9

    Default Can someone explain this code to me? (Includes Working Police Light Code)

    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}

  2. #2
    Wire Sofaking Unsmart's Avatar
    Join Date
    Dec 2008
    Location
    Belgium OR BANland
    Posts
    1,965

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    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

  3. #3
    Wire Sofaking ryland's Avatar
    Join Date
    Oct 2009
    Location
    Card bord box next to wal-mart.
    Posts
    594

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    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.

  4. #4
    Wiremod Helper Donkie's Avatar
    Join Date
    May 2008
    Location
    Sweden
    Posts
    1,661

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    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.

  5. #5
    Wire Sofaking ryland's Avatar
    Join Date
    Oct 2009
    Location
    Card bord box next to wal-mart.
    Posts
    594

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    Oh that's right I forgot, sorry for the bad info, its one am.

  6. #6
    Wire Sofaking Vbitz's Avatar
    Join Date
    Feb 2009
    Location
    NZ
    Posts
    685

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    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.

    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}
    that will make better sence
    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

    Quote Originally Posted by Bull View Post
    As example Jat Goodwin is "the official bastard of wiremod", but that isn't true.. He's very cute and huggable like a little puppy.

  7. #7
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    Quote Originally Posted by Vbitz View Post
    this is the sort of thing that is going to lag a bit on the servers
    What sort of sucky servers do you play on o.O? lol
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  8. #8
    Wire Sofaking Vbitz's Avatar
    Join Date
    Feb 2009
    Location
    NZ
    Posts
    685

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    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

    Quote Originally Posted by Bull View Post
    As example Jat Goodwin is "the official bastard of wiremod", but that isn't true.. He's very cute and huggable like a little puppy.

  9. #9
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    Quote Originally Posted by Vbitz View Post
    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
    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:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  10. #10
    Wire Sofaking ktccd's Avatar
    Join Date
    Sep 2009
    Posts
    751

    Default Re: Can someone explain this code to me? (Includes Working Police Light Code)

    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?

+ Reply to Thread
Page 1 of 3 123 LastLast

Similar Threads

  1. Police Light Expression
    By James8122 in forum Finished contraptions
    Replies: 1
    Last Post: 05-04-2009, 08:38 AM
  2. E2 Code not working
    By Teddypimm in forum Expression 2 Discussion & Help
    Replies: 4
    Last Post: 04-10-2009, 06:19 AM
  3. Blinking Light Code
    By Osetjka in forum Installation and Malfunctions Support
    Replies: 2
    Last Post: 02-06-2008, 12:21 PM
  4. Police light bars!
    By alangowski in forum Finished contraptions
    Replies: 11
    Last Post: 01-05-2008, 07:38 PM
  5. Police Light Bar (My Version)
    By occ in forum Finished contraptions
    Replies: 2
    Last Post: 01-02-2008, 04:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots