+ Reply to Thread
Results 1 to 5 of 5

Thread: How to import os in lua?

  1. #1
    Plane Touched
    Join Date
    Feb 2016
    Posts
    218

    Default How to import os in lua?

    When i execute: require "os" and turn on the add-on, it gives an error: attempt to call global 'require' (a nil value).

    Is this intended due to security reasons?
    How can i get the add-on to sleep for a second then?

  2. #2
    General of Telara
    Join Date
    Mar 2014
    Posts
    967

    Default

    Quote Originally Posted by Angelin View Post
    When i execute: require "os" and turn on the add-on, it gives an error: attempt to call global 'require' (a nil value).

    Is this intended due to security reasons?
    Yes, you can't use the OS or IO module because people could do stupid things with it.

    Quote Originally Posted by Angelin View Post
    How can i get the add-on to sleep for a second then?
    And this is exactly an example why those modules are disabled.
    Why on earth would you want to do that? You are aware that it would just freeze the client (until the watchdog steps in)?

    Besides that, lua's default OS module doesn't offer a sleep function anyway.

    I have no idea what you're trying to do, but generally speaking, everything in an addon is tied to some event, so you'll want to look for a suitable event to attach your actions to.

  3. #3
    Plane Touched
    Join Date
    Feb 2016
    Posts
    218

    Default

    Quote Originally Posted by Lynx3d View Post
    Yes, you can't use the OS or IO module because people could do stupid things with it.
    Since it's open source Rift should provide an option to allow permission elevation of an add-on in case that add-on need to access certain os functionalities (eg. logging to a file, hotkeys to activate the add-on instead of mouse-over etc).

    Quote Originally Posted by Lynx3d View Post
    And this is exactly an example why those modules are disabled.
    Why on earth would you want to do that? You are aware that it would just freeze the client (until the watchdog steps in)?

    Besides that, lua's default OS module doesn't offer a sleep function anyway.

    I have no idea what you're trying to do, but generally speaking, everything in an addon is tied to some event, so you'll want to look for a suitable event to attach your actions to.
    Well i thought add-ons are running on a separate thread so putting it to sleep won't freeze the client running in another thread. Seems like not the case.

    I'm not familiar with lua, but i did a search and found http://lua-users.org/wiki/SleepFunction.

    I'm working on a minion sender add-on, apparently the API does not provide a way to check if a 5/15min adventure needs credit, so the only way is:
    1. try to send the minion on that adventure
    2. wait till adventure id changes (with a small sleep so that the thread dont use too much cpu)
    3. if the timer (say, 1sec) runs out and the adventure id still doesnt change, shuffle the deck and start from step 1 again.

    This way, the user only have to click it once (which means only 1 event) instead of twice to ensure that a minion is successfully sent.



    Another alternative is to just shuffle it like 5 times to make sure the current adventure is non-credit, then send it. But this gives a bold red internal error message in the centre of the screen. Is there a way to disable that?

  4. #4
    Sword of Telara
    Join Date
    Sep 2014
    Posts
    888

    Default

    Quote Originally Posted by Angelin View Post
    I'm working on a minion sender add-on, apparently the API does not provide a way to check if a 5/15min adventure needs credit, so the only way is:
    1. try to send the minion on that adventure
    2. wait till adventure id changes (with a small sleep so that the thread dont use too much cpu)
    3. if the timer (say, 1sec) runs out and the adventure id still doesnt change, shuffle the deck and start from step 1 again.

    This way, the user only have to click it once (which means only 1 event) instead of twice to ensure that a minion is successfully sent.
    1) Attempt to send on adventure. Add something to a table indicating the stuff you need to check whether it worked or not, and the Inspect.Time.Frame you did it.
    2) Hook Event.System.Update.Begin (or whatever these things are called). Look up your table values, see if 1s has passed since you tried, if yes then check and do appropriate things.

    Well, that would be my solution, not sure how else to do it.
    Spellbook@Greybriar
    Rejuvenation@Greybriar

  5. #5
    General of Telara
    Join Date
    Mar 2014
    Posts
    967

    Default

    Quote Originally Posted by Angelin View Post
    Since it's open source Rift should provide an option to allow permission elevation of an add-on in case that add-on need to access certain os functionalities (eg. logging to a file, hotkeys to activate the add-on instead of mouse-over etc).
    Open source is no argument. Firefox and Chromium are also FOSS (while the Rift client isn't, only LuaJit) and still don't allow Java Script to mess up my system. It's called sandboxing and is done for good reasons. What happens if you mess up a sandbox can be seen with browser plugins like Flash and Java, some of the most common ways to compromise systems.

    So while you might have use for OS functionality and file I/O, others will find ways to abuse it, if not to compromise your system then to have an unfair advantage over other players (bots etc.)

    Quote Originally Posted by Angelin View Post
    Well i thought add-ons are running on a separate thread so putting it to sleep won't freeze the client running in another thread. Seems like not the case.

    I'm not familiar with lua, but i did a search and found http://lua-users.org/wiki/SleepFunction.

    I'm working on a minion sender add-on, apparently the API does not provide a way to check if a 5/15min adventure needs credit, so the only way is:
    1. try to send the minion on that adventure
    2. wait till adventure id changes (with a small sleep so that the thread dont use too much cpu)
    3. if the timer (say, 1sec) runs out and the adventure id still doesnt change, shuffle the deck and start from step 1 again.

    This way, the user only have to click it once (which means only 1 event) instead of twice to ensure that a minion is successfully sent.



    Another alternative is to just shuffle it like 5 times to make sure the current adventure is non-credit, then send it. But this gives a bold red internal error message in the centre of the screen. Is there a way to disable that?
    If you actually read the linked page, it clearly says there is no sleep and you have to resort to busy-waiting or making assumptions about the system you're running on, IMHO both unacceptable.

    But as said, addons don't behave like they are an own process/thread, that would just be overkill. What Foolio suggested is the only way to hook "background" tasks, i.e. check every rendered frame if you need to do something.

    But the alternative you suggested is exactly what I did a while ago, just try to shuffle each new adventure card. The red text is an annoyance, but it has the advantage that you'll never even get to see those annoying credit adventures even when you send minions manually.
    You don't have to guess the amount of shuffles either, just do it in Event.Minion.Adventure.Change(). If nothing happens, no change event will happen.

+ Reply to 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