+ Reply to Thread
Results 1 to 4 of 4

Thread: Automatic Train Expression Help

  1. #1
    Wirererer Tommyx50's Avatar
    Join Date
    Oct 2007
    Location
    Edinburgh, Scotland
    Posts
    229
    Blog Entries
    1

    Question Automatic Train Expression Help

    I really need help with this E2 code that I started making.
    For some reason this code acts weirdly. If I have a ranger, and all the colours are correct, it still outputs 1 to "Go".
    If I refresh the chip, it seems to correct itself, and if I take it away from the ranger it goes back to 1 as usual, but if I put it back in it stays as one. Any help?

    Code:
    @name Automatic Train Expression
    @inputs ColR ColG ColB
    @outputs Thruster Thruster2
    @persist Go
    
    runOnTick(1)
    
    if(ColR==50 & ColG==50 & ColB==50) {timer"Go=0",2000}
    else {Go=1}
    
    if(Go==1)
    {
        Thruster=1
        Thruster2=1
    } 
    else
    {
        Thruster1=0
        Thruster2=0
    }
    I have tried with and without the timer for "Go", but nothing changes.
    Expression 3 GATE


    -Something to remember. We cannot see your information through this. Only you (and G. Bush) can.

  2. #2
    Wiremod Helper Lyinginbedmon's Avatar
    Join Date
    Mar 2009
    Location
    England
    Posts
    2,659

    Default Re: Automatic Train Expression Help

    Because you have nothing to tell it to set Go to 0.

    The Olympus Technologies drones, totally not SkyNet in Gmod form.
    Cronus: The Ultimate Drone, definitely SkyNet in Gmod form.
    The gBrain Project, the drone controls system that thinks it's better than you

  3. #3
    Wirererer cooldudetb's Avatar
    Join Date
    Sep 2008
    Location
    UK
    Posts
    253

    Default Re: Automatic Train Expression Help

    You seem to misunderstand the use of timers.

    When you set a timer, you give it a name and a time in milliseconds until it activates.
    When a timer activates, it triggers the execution of the code. You can check whether the execution is caused by a timer by using clk().

    Also, runOnTick is not necessary for this chip.
    You also had Thruster1 = 0 (There is no Thruster1).

    The follow code should work:

    Code:
    @name Automatic Train Expression
    @inputs ColR ColG ColB
    @outputs Thruster Thruster2
    @persist Go
    
    if(ColR==50 & ColG==50 & ColB==50) {
        Go = 0
        timer("Go",2000)
    }
    
    if (clk("Go")) {
        Go = 1
    }
    
    if(Go==1)
    {
        Thruster=1
        Thruster2=1
    } 
    else
    {
        Thruster=0
        Thruster2=0
    }
    [E2] Extended Timers

    Bulls pro-tip of the day:
    When you honestly think that Led3=1,0,1,0,1,0,1 can make a light blink, stop trying to make an OS and do something easier.

  4. #4
    Wirererer Tommyx50's Avatar
    Join Date
    Oct 2007
    Location
    Edinburgh, Scotland
    Posts
    229
    Blog Entries
    1

    Default Re: Automatic Train Expression Help

    Thanks, I am new to E2...

    Also, Lyinginbedmon, it is there.

    And I tried with and without the timer, so it was because I am an idiot sometimes and had Thruster1 for the else{} bit.
    Expression 3 GATE


    -Something to remember. We cannot see your information through this. Only you (and G. Bush) can.

+ Reply to Thread

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