Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: .LUA: Trouble with nil value

  
  1. #1
    Organized_Chaos's Avatar
    Organized_Chaos is offline Senior Member -Hacks Titan
    Join Date
    May 2008
    Posts
    4,768
    Rep Power
    53963

    Default

    Hello everyone.. As you can probably tell I am new at LUA programing. I followed all the directions in this tutorial at http://www.evilmana.com/tutorials/lua_tutorial_03.php and I am having problems. How do I make this error go away and make my "program" work?
    I get an error message that says
    "Error: Variable Tut.LUA:18: attempt to perform arithmetic on global 'myBirthYear' (a nil value)
    Press start to restart"

    ("Variable Tut.LUA" is my file name.)
    -
    Here is my code:
    Code:
    -- NOTES
    -- Green Color Object
    green = Color.new(0, 255, 0)
    
    -- Store birth year in variable myBirthYear
    myBirthyear = 1991
    
    -- Store current year in currentYear
    currentYear = 2008
    
    -- create an empty variable
    myAge = nil
    
    -- Store some text in a variable (Note the 
    
    space after the last word before the end ")
    someText = "My age is roughly "
    
    -- Subtract myBirthYear from currentYear 
    
    and store in myAge
    myAge = currentYear - myBirthYear
    
    -- Print our text variable to the screen 
    
    (NOTE that there are no "" surrounding 
    
    someText)
    screen:print(10,100,someText .. 
    
    myAge,green)
    
    -- Buffer offscreen to onscreen (If this 
    
    was a human, offscreen would be thinking 
    
    about it, onscreen would be saying it)
    screen.flip()
    -- Loop forever
    while true do
    screen.waitVblankStart()
    end
    The only thing I did differently was use my birth year and the current year instead of the years in this tutorial. And I added a few custom notes using the "-- text" format. Since this was a tutorial I figured I might add in a few things in case I use this file later as a reference or something. That stuff shouldn't make a difference should it?


  2. #2
    hotrocker is offline Programmer -Hacks Ninja
    Join Date
    Jun 2007
    Location
    yesterday
    Posts
    721
    Rep Power
    13

    Default

    we have a lua section ;)

    (Compliments of Chode)

  3. #3
    Organized_Chaos's Avatar
    Organized_Chaos is offline Senior Member -Hacks Titan
    Join Date
    May 2008
    Posts
    4,768
    Rep Power
    53963

    Default

    Yes I see that. Sorry :)

  4. #4
    hotrocker is offline Programmer -Hacks Ninja
    Join Date
    Jun 2007
    Location
    yesterday
    Posts
    721
    Rep Power
    13

    Default

    repost it over there for now and this one'l get deleted next time a mod is on

    (Compliments of Chode)

  5. #5
    RazorChrist's Avatar
    RazorChrist is offline -Hacks Smarty
    Join Date
    Jan 2008
    Location
    Tulsa, OK
    Posts
    194
    Rep Power
    13

    Default

    Chaos, here's part, if not all, of the problem...look at your math, versus how your variable is setup:

    Code:
    -- Store birth year in variable myBirthYear
    myBirthyear = 1991
    
    and store in myAge
    myAge = currentYear - myBirthYear
    Notice that when you setup your variable, it's spelled "myBirthyear" with a lower case Y in year....but in your math, you have an upper case Y. Try changing the Y in your variable setup to an upper-case Y and see if that fixes the issue. Case-sensitive is a bitch sometimes.

    PS2 = Softmodded Slim w/ Free MCBoot v1.8b
    PSP = Phat 5.00 m33-6 w/ 1.50 Kernel Addon
    WII = Softmodded v4.1u w/ HBC v1.0.8 + USBConfig Loader v56 + 300gb External Drive

  6. #6
    Organized_Chaos's Avatar
    Organized_Chaos is offline Senior Member -Hacks Titan
    Join Date
    May 2008
    Posts
    4,768
    Rep Power
    53963

    Default

    Damn, can't believe I missed that. I knew everything was case sensitive.. I just over looked that.
    Thanks I changed that and it worked fine.

  7. #7
    Blade_punk's Avatar
    Blade_punk is offline Programmer -Hacks Guru
    Join Date
    Nov 2006
    Location
    Candy Mountain
    Posts
    2,314
    Rep Power
    16

    Default

    Il move just so anyone else who visits the LUA Section with the same error can find this

    -Rock Station-
    PSN: Xsjado7


  8. #8
    RazorChrist's Avatar
    RazorChrist is offline -Hacks Smarty
    Join Date
    Jan 2008
    Location
    Tulsa, OK
    Posts
    194
    Rep Power
    13

    Default

    Haha, yeah I miss stupid crap like that all the time till I start getting errors on compile/runtime. You just have to go all the way back through, line by line, usually looking for a missing equals sign or semi colon.

    PS2 = Softmodded Slim w/ Free MCBoot v1.8b
    PSP = Phat 5.00 m33-6 w/ 1.50 Kernel Addon
    WII = Softmodded v4.1u w/ HBC v1.0.8 + USBConfig Loader v56 + 300gb External Drive

  9. #9
    Organized_Chaos's Avatar
    Organized_Chaos is offline Senior Member -Hacks Titan
    Join Date
    May 2008
    Posts
    4,768
    Rep Power
    53963

    Default

    Is C or C++ coding case sensitive like this? Are all programing languages like that? I am use to HTML where most of the time everything is either all lowercase or all uppercase. HTML is the only code I am somewhat use to writing.. But I'm no expert on it either.

  10. #10
    RazorChrist's Avatar
    RazorChrist is offline -Hacks Smarty
    Join Date
    Jan 2008
    Location
    Tulsa, OK
    Posts
    194
    Rep Power
    13

    Default

    Not sure about "most" but usually unless it's a web-based scripting, it's usually case sensative. I know C++ and C are for sure.

    PS2 = Softmodded Slim w/ Free MCBoot v1.8b
    PSP = Phat 5.00 m33-6 w/ 1.50 Kernel Addon
    WII = Softmodded v4.1u w/ HBC v1.0.8 + USBConfig Loader v56 + 300gb External Drive

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •