+ Reply to Thread
Results 1 to 6 of 6

Thread: E2 Lua Error Help

  1. #1
    Wire Sofaking Officer Tibbles will become famous soon enough Officer Tibbles's Avatar
    Join Date
    Aug 2008
    Location
    San Diego, Kalifornien
    Posts
    528

    Default E2 Lua Error Help

    I'm working on a calculator that is based in my OS, and I got the code written out, but there's a problem.

    I get these Lua errors..

    Code:
    entities\gmod_wire_expression2\core\number.lua:109: attempt to perform arithmetic on a nil value
    
    Timer Error: entities\gmod_wire_expression2\core\number.lua:109: attempt to perform arithmetic on a nil value
    
    The part of my code that does the calculations is as follows

    Code:
    if(Word=="-mult"&Key==13){
    A=ceil((A-1)/30)*30+0
    Busy=1
    PrintColor=18
    Print="Multiplication                Enter Numbers"
    Word=""
    Mult=1
    }
    
    if(Key==13&Mult==1){
    A=ceil((A-1)/30)*30+0
    PrintColor=666
    Busy=1
    Print = Answer
    AN = Number * Number
    Number = Word:toNumber()
    Answer = toString(AN)
    }
    
    So, yea help will be appreciated.
    No

  2. #2
    Newbie Programmer
    ZeikJT will become famous soon enough ZeikJT's Avatar
    Join Date
    Dec 2008
    Location
    California
    Posts
    1,235

    Default Re: E2 Lua Error Help

    It seems like you are trying to multiply by a number that is nil.
    I honestly thought it was impossible for that to happen in E2 as all number variables that get defined are supposed to start with a value of 0.

    Make sure all the variables you are working with have valid values. Does Number have a value? It could be there when the multiplication gives an error. It might be this part too:
    A=ceil((A-1)/30)*30+0

    Which by the way is weird, why would you add 0? You don't need it.

    I'll see if I can determine anything.

    EDIT: Yeah, it seems that if a string is "" it can be converted to nil.
    Last edited by ZeikJT; 02-15-2009 at 09:45 PM.
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

    The flame puts me in the mood to "Do it!".
    -Dart, Legend of Dragoon

  3. #3
    Spucatum Tauri
    Bull is a splendid one to behold Bull is a splendid one to behold Bull is a splendid one to behold Bull is a splendid one to behold Bull is a splendid one to behold Bull is a splendid one to behold Bull is a splendid one to behold Bull's Avatar
    Join Date
    Jun 2008
    Location
    Finland
    Posts
    3,464

    Default Re: E2 Lua Error Help

    Code:
    AN = Number * Number
    Number = Word:toNumber()
    
    Shouldn't those two be switched?

    And you second comparison is run too early.

    if(Word=="-mult"&Key==13){
    A=ceil((A-1)/30)*30+0
    Busy=1
    PrintColor=18
    Print="Multiplication Enter Numbers"
    Word="" # Here you empty the string
    Mult=1 # Here you set mult to 1
    }

    if(Key==13&Mult==1){ # So this comparison returns true
    A=ceil((A-1)/30)*30+0
    PrintColor=666
    Busy=1
    Print = Answer
    AN = Number * Number
    Number = Word:toNumber() # and this tries to convert a empty string to a number.
    (Since you emptied the string earlier) Which gives the error probably.

    Answer = toString(AN)
    }

    Why do you set the Print string to answer before calculating it?
    My signature has a point.
    Quote Originally Posted by Squeakyneb View Post
    when l3ulletje says do it, do it.
    That
    The Great Report Button Quiz.

  4. #4
    Wire Sofaking Whodunnit will become famous soon enough Whodunnit's Avatar
    Join Date
    Jan 2008
    Location
    New Zealand, Ackl
    Posts
    482

    Default Re: E2 Lua Error Help

    word = "" might count as nil ?

  5. #5
    Wire Sofaking Officer Tibbles will become famous soon enough Officer Tibbles's Avatar
    Join Date
    Aug 2008
    Location
    San Diego, Kalifornien
    Posts
    528

    Default Re: E2 Lua Error Help

    Quote Originally Posted by l3ulletje View Post
    Code:
    AN = Number * Number
    Number = Word:toNumber()
    
    Shouldn't those two be switched?

    And you second comparison is run too early.

    if(Word=="-mult"&Key==13){
    A=ceil((A-1)/30)*30+0
    Busy=1
    PrintColor=18
    Print="Multiplication Enter Numbers"
    Word="" # Here you empty the string
    Mult=1 # Here you set mult to 1
    }

    if(Key==13&Mult==1){ # So this comparison returns true
    A=ceil((A-1)/30)*30+0
    PrintColor=666
    Busy=1
    Print = Answer
    AN = Number * Number
    Number = Word:toNumber() # and this tries to convert a empty string to a number.
    (Since you emptied the string earlier) Which gives the error probably.

    Answer = toString(AN)
    }

    Why do you set the Print string to answer before calculating it?
    Wow, Thanks. I'll try that. I always thought that declaring Word as "" then it meant that nothing is changed to it.


    And Zeik... The whole


    Code:
    A=ceil((A-1)/30)*30+0
    
    Is just a formula, so if I wanted it to skip lines, I would change the +0 to +1, But I just Copy / Paste that thing in there.
    No

  6. #6
    Expressionism 2.0

    Syranide has disabled reputation Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,179

    Default Re: E2 Lua Error Help

    I've committed a fix that prevents toNumber() from returning nil, it returns 0 instead.

+ Reply to Thread

Similar Threads

  1. normal commands E2 error or scrip error?!?!?!!?
    By oenmaster in forum Bug Reports
    Replies: 3
    Last Post: 01-17-2009, 07:08 AM
  2. Adv Dup Error
    By Captain Maim in forum Help & Support
    Replies: 3
    Last Post: 10-26-2008, 10:29 AM
  3. Error
    By Avengermac in forum Help & Support
    Replies: 3
    Last Post: 08-28-2007, 03:56 PM
  4. Nil Value Error
    By StealthAssassin in forum Help & Support
    Replies: 4
    Last Post: 08-02-2007, 04:50 AM
  5. CPU Error..
    By mad_sprayer in forum Help & Support
    Replies: 6
    Last Post: 03-30-2007, 04:23 PM

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