Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

DeGariless

Members
  • Content Count

    3
  • Joined

  • Last visited

Posts posted by DeGariless

  1. I'll use short example programs to explain exactly what I am trying to achieve.

     

    I have a a file test.lua that looks like this

    testAPI = require("testAPI")
    
    testAPI.talk()
    testAPI.setWord("Goodbye")
    testAPI.talk()
    

    I also have a file /lib/testAPI.lua that looks like this

    testAPI = {}
    
    local word = "Hello"
    
    function testAPI.talk()
      print(word)
    end
    
    function testAPI.setWord(s)
     word = s
    end
    
    return testAPI
    

    when I run test.lua for the first time I get the output

    Hello

    Goodbye

     

    but than I run it a second time and I get

    Goodbye

    Goodbye

     

    How can I get the variable 'word' to reset anytime a new program uses that API?

  2. How many players are in your list "playerData.players"?

    You are using insertion sort to sort this list. This is quite slow for big lists. (time: n² with n as the size of the list, table.sort() uses a better sorting algorithm, n * log(n) )

    But unless you have a very big list of users it probably isn't the reason

     

    There are about 30 players in the PlayerData.json file at the moment. I realize that as the number grows, it will become a problem. I plan to have some players automatically removed, or moved to a separate inactive players file of some sort. Thanks for the tip about sorting the table more efficiently. I'll I'll have to take that into consideration in the future.  

     

    Another performance hint:

    You can process the list returned by od.getPlayerList() before you continue using it:

     

    But again I'm not sure if your player list is really that big.

     

    Don't know why I didn't think of that.

     

     

    Here are some other hints:

    1. You can use "xpcall(main, debug.traceback)" for more detailed information than "pcall(main)".
    2. It would also help if you add some kind of logging to your program. (open a file with append mode and write something to the file before and after critical/suspicious parts of your code. (don't forget to do file:flush() after file:write() to ensure that there is no delayed writing)

    xpcall(main, debug.traceback) is exactly what I was originally looking for. Thanks :)

     

     

    Thanks for all the tips. I really appreciate it, but unfortunately my problem is still not solved. The computer will still shut down and show "too long without yielding" even when it's left idling without running anything other than OpenOS. I'm now thinking that is has something to do with when the server does it's backup. Backup causes lag, lag causes computer to error out. There must be some way to prevent this from happening or to automatically restart the computer every so often. I'd like to assume that the computer needs to calculate how much time it's taking on an operation based on in game time instead of real world time.

  3. So, I wrote the program for the spawn computer of a server I play on. Shows rules, announcements etc. Here is is in case you care to look.

     

    http://pastebin.com/QYpCrzEp

     

    The program runs great for long periods of time, but will randomly show the error "Too long without yielding". It has plenty of os.sleep(x) calls to prevent it from erroring. You can see I have added some extra code near line 365 in hopes to prevent the computer from erroring out. It didn't seem to help nearly as much as I hoped. I think it has to do with when the server lags. Anyone know how to fix this? Thanks.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.