WorkQueue.Request function in lua_function_list.txt

Discussion about Mods for Prison Architect

Moderator: NBJeff

lodestar
level0
Posts: 6
Joined: Tue Nov 19, 2013 2:39 pm

WorkQueue.Request function in lua_function_list.txt

Postby lodestar » Thu Sep 15, 2016 4:44 am

So, I'm trying to write a mod to automatically search every prisoner that goes through a corridor. While exploring the lua functions, looking for a way to create the search job in the queue, I found the WorkQueue.Request function in the Lua_function_list.txt file, but when I try to use that, there's no such global WorkQueue. Does that really exists? Is there any other way I can create the job directly? I also tried with prisoner.CreateJob("SearchObject"), but it doesn't work. I can get a custom job performed by a guard and then check for contraband through GetProperty, but the ideal would be the default Search.
lodestar
level0
Posts: 6
Joined: Tue Nov 19, 2013 2:39 pm

Re: WorkQueue.Request function in lua_function_list.txt

Postby lodestar » Fri Sep 16, 2016 5:56 am

Since yesterday I've been trying to detect contraband "manually", through GetProperty, but there's no way to do that either. Save files have a TheftItem property for prisoners, but that's not available on the API.

I'm starting to think the devs intentionally left out of the API all means to automatically detect contraband, to prevent the creation of mods that would allow someone to automate the game almost completely.
murgh
level2
level2
Posts: 228
Joined: Sat Jan 30, 2016 11:52 am

Re: WorkQueue.Request function in lua_function_list.txt

Postby murgh » Sat Sep 17, 2016 10:43 am

Tried to mess with WorkQueue as well but it spits out this error:

Code: Select all

ScriptSystem Error : RUNTIME ERROR : [string "..."]:1559: attempt to index global 'WorkQueue' (a nil value)


No idea what I'm doing wrong, lol. Apparently WorkQueue.Request("SearchObject", this) doesn't work,
nor will WorkQueue.Request("SearchObject", thatPrisoner) when running a for loop after doing a GetNearbyObjects() scan for prisoners.
Both will output same error, like WorkQueue doesn't exist at all. How to use this function?
User avatar
Ghost314
level1
level1
Posts: 24
Joined: Thu Dec 24, 2015 9:23 pm

Re: WorkQueue.Request function in lua_function_list.txt

Postby Ghost314 » Thu Sep 22, 2016 7:42 pm

I checked the in-game script debugger window and it looks like there is no WorkQueue defined in the global scope, which explains the error messages. It's a shame, since that function would have made my life a whole lot easier. :(
User avatar
Ghost314
level1
level1
Posts: 24
Joined: Thu Dec 24, 2015 9:23 pm

Re: WorkQueue.Request function in lua_function_list.txt

Postby Ghost314 » Thu Sep 22, 2016 9:09 pm

I discovered the answer by accident :lol: in update 8, introversion added the ability to define a World.lua script:

- Lua World Scripts
Each mod can now have a data/world.lua script file, which should contain both Init() and Update( timePassed ) functions.
This script is initialised on World initialisation (for both new maps and loaded save games) and Updated on each World update.
Variables set in the "this" or "World" tables will be cast to strings and persist in the save game.
Variables are loaded after Init and before the first call to Update.


Apparently the WorkQueue is visible to the special World.lua script, but not to any of your other scripts.
murgh
level2
level2
Posts: 228
Joined: Sat Jan 30, 2016 11:52 am

Re: WorkQueue.Request function in lua_function_list.txt

Postby murgh » Sat Sep 24, 2016 8:50 am

Any examples on how to use that stuff would be more than welcome.
User avatar
Ghost314
level1
level1
Posts: 24
Joined: Thu Dec 24, 2015 9:23 pm

Re: WorkQueue.Request function in lua_function_list.txt

Postby Ghost314 » Sat Sep 24, 2016 5:07 pm

murgh wrote:Any examples on how to use that stuff would be more than welcome.


I have been on the hunt for that info myself, and so far have come up dry. I watched the entire dev blog video on that release, but they kind of glossed over the world scripts feature, saying only that it was intended to resolve a common hack where modders would want to have only one instance of a script running, so they would have to spawn a single object somewhere to attach the script to.

This is something I could definitely use, but I can't find any further info on it, so I just started experimenting with it myself. So far what I have discovered is:
  • In addition to WorkQueue.Request, there are a number of special functions in the Game table that are only visible to World scripts (some of which look very interesting)
  • World scripts are not attached to a traditional 'game object'/Entity, a call to 'this.GetNearbyObjects()' will fail from within a world script
  • Calling this.getNearbyObjects("World",x) from inside traditional scripts attached to regular Entities doesn't seem to yield any results

My current focus is in trying to figure out how to get a reference to a regular game object from within the world script, or a reference to the world script from within a regular game object, as I need some sort of communication between my regular scripts and the world script in order to make proper use of it. Since some of the parameters to WorkQueue.Request are potentially object tables, I assume there must be a way to do it, but the traditional mechanism of 'GetNearbyObjects' does not seem to be working.

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 1 guest