Idle scripting issue

Discussion about Mods for Prison Architect

Moderator: NBJeff

GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Idle scripting issue

Postby GamingBud » Sun Jan 04, 2015 11:43 pm

Hello, me again!? Bah.

I was trying to script a looping idle movement for my new staff member, but the debugger says that one of the functions is unknown. I needed a wait function to spread out the movement, so that may be the problem, but i got that function from a website. Would someone mind checking this code for me and maybe revising it?

Code: Select all

function Create()
  Object.ApplyVelocity(1, 0, false)
  Turn1 = true
end

if Turn1 = true then
function Wait(2)
  Object.ApplyVelocity(0, 0, false)
  Turn2 = true
end

if Turn2 = true then
function Wait(2)
  Object.ApplyVelocity(-1, 1, false)
  Turn3 = true
  Turn1 = false
end

if Turn3 = true then
function Wait(2)
  Object.ApplyVelocity(0, 0, false)
  Turn4 = true
  Turn2 = false
end

if Turn4 = true then
function Wait(2)
  Object.ApplyVelocity(0, 1, false)
  Turn5 = true
  Turn3 = false
end

if Turn5 = true then
function Wait(2)
  Object.ApplyVelocity(0, 0, false)
  Turn6 = true
  Turn4 = false
end

if Turn6 = true then
function Update(timePassed)
  Object.ApplyVelocity(1, 0, false)
   function Wait(2)
     Turn1 = true
     Turn5 = false
end


The "Turn1-6" are variables to set when the object will apply that new velocity

The last one is an update function because i needed that to loop it back around.

The function Wait(2) is supposed to make to script stop for 2 seconds and then continue on, so its not a jerky movement.
User avatar
xander
level5
level5
Posts: 16869
Joined: Thu Oct 21, 2004 11:41 pm
Location: Highland, CA, USA
Contact:

Re: Idle scripting issue

Postby xander » Mon Jan 05, 2015 12:31 am

I believe that it was noted in the last alpha video that Prison Architect only implements a subset of all lua commands (to do otherwise would invite the creation and spread of malicious scripts that could cause all kinds of damage). It is possible, I suppose, that wait() is one of the commands that was not implemented? If that really is the case, it seems like it should be implemented---submit a bug report/feature request to the Mantis Tracker.

xander
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: Idle scripting issue

Postby GamingBud » Mon Jan 05, 2015 4:51 am

Is there a workaround code???
User avatar
Chad
level3
level3
Posts: 255
Joined: Wed Sep 26, 2012 8:00 pm

Re: Idle scripting issue

Postby Chad » Mon Jan 05, 2015 7:36 am

No need for a custom loop here. You've got the Update() function, which is basically a loop. If the interval is to short, add at timer like timer = 5 for 5 seconds. Then check if the timer is <= 0 and do your stuff an reset the timer. Else decrease the timer by timePassed. Very simple.

Good luck
Puman
level1
level1
Posts: 48
Joined: Fri Aug 29, 2014 1:21 pm

Re: Idle scripting issue

Postby Puman » Mon Jan 05, 2015 8:46 pm

Chad wrote:No need for a custom loop here. You've got the Update() function, which is basically a loop. If the interval is to short, add at timer like timer = 5 for 5 seconds. Then check if the timer is <= 0 and do your stuff an reset the timer. Else decrease the timer by timePassed. Very simple.

Good luck

Most of my objects have an interval updater so they only perform their main code every now and then, thus sparing the CPU:

Code: Select all

local timer = 0
local nextTimeout = 0.1

function Update(timePassed)
    timer = timer + timePassed;
    if timer > nextTimeout then
        nextTimeout = IntervalUpdate(timer)
        timer = 0
    end
end

function IntervalUpdate(timePassed)
    -- will be called again in 1 time
    return 1
end
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: Idle scripting issue

Postby GamingBud » Mon Jan 05, 2015 9:10 pm

Awesome, thank you. Could you explain how i would go by making the staff member move different directions with this code though since i'm a noob with coding?
efagcollege
level0
Posts: 3
Joined: Tue Jan 20, 2015 10:15 am

Re: Idle scripting issue

Postby efagcollege » Thu Jan 29, 2015 2:24 pm

I am also having the same problem.Thanks for all friends.

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 5 guests