Modifying Needs Error -- Help Needed

Discussion about Mods for Prison Architect

Moderator: NBJeff

NativeFighter
level1
level1
Posts: 14
Joined: Tue Sep 08, 2015 12:08 am

Modifying Needs Error -- Help Needed

Postby NativeFighter » Sun Jul 31, 2016 12:21 am

Greetings,

I was trying to use a loop to go through all needs and do stuff with them when I fell upon this error here:

Code: Select all

ScriptSystem Error : RUNTIME ERROR : [string "function this.Needs.NeedsMetaTable:__index(..."]:3: attempt to index field 'UNUSED' (a nil value)


Now, this error appeared even if the only code I had within the loop was:
local alcoholNeed = this.Needs.Alcohol or 0

So if anyone here knows why that is happening please let me know asap as I want to update my mod before leaving on holidays!

Kind regards,
Native.
murgh
level2
level2
Posts: 232
Joined: Sat Jan 30, 2016 11:52 am

Re: Modifying Needs Error -- Help Needed

Postby murgh » Sun Jul 31, 2016 9:42 am

Check if the value is nil instead of 0. That should help I guess.
NativeFighter
level1
level1
Posts: 14
Joined: Tue Sep 08, 2015 12:08 am

Re: Modifying Needs Error -- Help Needed

Postby NativeFighter » Sun Jul 31, 2016 3:45 pm

murgh wrote:Check if the value is nil instead of 0. That should help I guess.

Nope... didn't work.

I can set a need the same way... but it seems to refuse for me to get that need.

EDIT: This happens also when I try to get a StatusEffect.
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Re: Modifying Needs Error -- Help Needed

Postby elDiablo » Mon Aug 01, 2016 10:07 am

We do "funky" stuff with metatables in Lua for access our variables. Can you give me an example of the loop you're using so I can reproduce the problem locally and get a fix?
NativeFighter
level1
level1
Posts: 14
Joined: Tue Sep 08, 2015 12:08 am

Re: Modifying Needs Error -- Help Needed

Postby NativeFighter » Wed Aug 03, 2016 5:15 pm

elDiablo wrote:We do "funky" stuff with metatables in Lua for access our variables. Can you give me an example of the loop you're using so I can reproduce the problem locally and get a fix?


This is my code:

Code: Select all

local rdm = math.random
local happynessFactor = 0

local needsList = {
       "Freedom",
   "Sleep",
   "Food",
   "Hygiene",
   "Comfort",
   "Literacy",
   "Safety",
   "Bowel",
   "Privacy",
   "Clothing",
   "Drugs"
}

      for i in next, needsList do
         local theNeed = needsList[i]
         debugText2 = (theNeed or 'Need Filled')
         
         if this.Needs.theNeed >= 0.5 then
            happynessFactor = happynessFactor + rdm(15,30)
         else
            happynessFactor = happynessFactor - rdm(15,30)
         end
      end
murgh
level2
level2
Posts: 232
Joined: Sat Jan 30, 2016 11:52 am

Re: Modifying Needs Error -- Help Needed

Postby murgh » Mon Aug 15, 2016 11:03 pm

elDiablo wrote:We do "funky" stuff with metatables in Lua for access our variables. Can you give me an example of the loop you're using so I can reproduce the problem locally and get a fix?



"Funky stuff indeed" :lol:
Another example, there is this Needs.Action thingy in de savedgame with several values like Use, Do-Regime etc, but it doesn't seem to have effect when messing with it, unless perhaps setting a corresponding number would do the trick. For the evacuation alarm I tried to change a prisoners Needs.Action into an action specified in needs.txt, in the hope he would go to a Provider to fulfil this need - but it didn't work. I could only pump up his 'evacuation' need but not set the action 'evacuate' as well so he would immediately leave work/reform/canteen/yard/etc to go evacuate. Instead his 'evacuation' need will be skyhigh and he will determine by himself when he wants to go run. Tough guys, those prisoners. :mrgreen:

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 4 guests