Lua file system functions don't work

So I wanted to mod Sandbox+ to make one of the unused key combinations load a Lua script from a file and run it, so I can test Lua commands without having to keep restarting Saints Row 3. Thankfully Lua provides a function (dofile) specifically for this purpose. Now when I pressed the key combination, nothing happened. Nothing, that is, except that Sandbox+ stopped responding to key presses. I had to restart the game in order for it to work. I tried another key combination to verify that yes, Sandbox+ was running properly, and then tried my key combination again. Sure enough, it stopped responding.

I tried modifying the Lua script a bit and figured out that dofile was what was causing the problem. Okay, I figured, I'll see if io.open works. No luck—same problem. I tried using both a relative and absolute path too, in case it was an issue with the current directory.

So what I'm asking is does anybody know how to access the file system from a Lua script in Saints Row 3? Barring that, is there any way to get a text string from the user in a script (such as an in-game text input function like you use to name an outfit, or even something in an external application) without having to restart the game each time?

Also, in case this isn't possible, I have to give IdolNinja props for dealing with this when making Sandbox+. You must have the patience of a Saint. ;-) Great job either way.
 
You keep asking and I keep telling you that it's not possible. But hey, don't take my word for it. Keep on seeing what you can do. I don't listen to naysayers either, and often find interesting solutions when I have to think outside the box. Best of luck.
 
You keep asking and I keep telling you that it's not possible. But hey, don't take my word for it. Keep on seeing what you can do. I don't listen to naysayers either, and often find interesting solutions when I have to think outside the box. Best of luck.

You said it's not possible to have an in-game Lua console. I don't believe you said anything about reading from files (correct me if I'm wrong.)
 
You said it's not possible to have an in-game Lua console. I don't believe you said anything about reading from files (correct me if I'm wrong.)

Fair enough.
 
Okay, so when the game needs the user to enter text, it uses the function game_vkeyboard_input. An example from store_clothing.lua can be seen at http://pastebin.com/CFPNs9yQ.
Problem is, I tried copying this call verbatim into sr3_city.lua with a different callback function I defined, but that just results in the same problem as with dofile. Also I don't know exactly what to do with VKEYBOARD_RESULTS—it's given as input to various ingame functions and seems to be an internal variable. It could be accessible as a plain Lua variable, considering it passes the name of the callback function as a string instead of a Lua function object.
 
I believe that it's a matter of scope. You simply can't call any menu related functions (like the ones from store_clothing.lua) from the sr3_city.lua script input threads. Believe me, I tried all this long ago.

EDIT:
Though... hmm... it may be worth a try to create a thread within the menu script itself and see if you can do anything with it.

EDIT:
Or, perhaps use one the core lua scripts to create a monitoring thread instead of sr3_city.lua, like maybe game_lib.lua
 
I'm afraid I don't really know how to do that...I don't really know much about SR3's Lua functions. I just copied what I saw in one of the scripts.
 
In case this is what you're thinking about... The separate Lua environments (city and menu) don't share functions or variables; i think they're literally two separate instances of the Lua engine or memory spaces. There wouldn't be a way for a thread in one environment to communicate with one in the other.

If i misinterpreted that, of course, never mind.
 
I just wanted to drop in and confirm the suspicions that there are in fact two entirely separate Lua states in the SR engine. There is the Interface Lua state for all of the interface scripts, and the Gameplay Lua state for all gameplay scripts. While some system level SR functions (such as thread_new()) are registered in both states, there is no way for a script in one state to interact directly with anything in the other state.

Additionally, because of memory constraints most of the standard Lua libraries are not included with the implementation of Lua for SR. The I/O library is one that is NOT included with SR's Lua implementation, which is why io.open() does not work.
 
Back
Top