Data Realms Fan Forums
http://forums.datarealms.com/

Lua trouble.
http://forums.datarealms.com/viewtopic.php?f=73&t=14710
Page 1 of 1

Author:  CrazyMLC [ Sun May 17, 2009 6:38 am ]
Post subject:  Lua trouble.

Please move to lua scripting!

Okay, I'm on my first steps towards learning lua and I try to imitate another section of code for practice... and it doesn't work.

Code:
function Create(self)
   self.SlowMoModifier = 0.01
   self.AIMode = 1
end

function Update(self)
   if self.IsPlayerControlled then
           TimerMan.TimeScale = self.SlowMoModifier;
     else
           TimerMan.TimeScale = 1.00
       end

   if self.IsDead then
           TimerMan.TimeScale = 1.00
       end
end

I probably have some huge mistake that I can't see.

Author:  Grif [ Sun May 17, 2009 6:50 am ]
Post subject:  Re: Lua trouble.

Well uh the fact that you're setting timescale on yourself on an update frame will auto-magically make it run as long as your alive.

Once your dead it'll stop.

Thus you could uh just have it be:

Code:
function Update(self)
TimerMan.TimeScale = 0.01;
end


Coincidentally, you're missing a bunch of semicolons. They're rather important.

Author:  CrazyMLC [ Sun May 17, 2009 7:15 am ]
Post subject:  Re: Lua trouble.

Hm.
Good to know.
I guess coding off the Wiki is like trying to live only on water for a month.

I really need to go through the entire Wiki and make sure when I try things that I am not taking the long route.

EDIT: Tested it, and it slows down even when the actor is not selected... i'll try to fix that on my own. I'll edit or post again if I find myself failing.

Author:  CrazyMLC [ Sun May 17, 2009 7:58 pm ]
Post subject:  Re: Lua trouble.

Sorry for the double post, but why doesn't this work? >_>
Code:
function Update(self)
if self.IsPlayerControlled then;
TimerMan.TimeScale = 0.1
else
TimerMan.TimeScale = 1
end

Author:  Grif [ Sun May 17, 2009 11:45 pm ]
Post subject:  Re: Lua trouble.

Let's count.

FUNCTION - opens a statement
IF - opens a statement
END - ends one statement
??? - does not end a statement

needs more ends

Also better tabbing.

Author:  CrazyMLC [ Sun May 17, 2009 11:48 pm ]
Post subject:  Re: Lua trouble.

An extra end...
ok, ok.
I'll try it out...

No dice
Code:
function Update(self)
   if self.IsPlayerControlled then;
      TimerMan.TimeScale = 0.1
else
      TimerMan.TimeScale = 1
   end
end

(Man I suck at coding!)
Is the "IsPlayerControlled" part being used correctly?
The problem is that it never slows down.

Author:  Grif [ Mon May 18, 2009 12:14 am ]
Post subject:  Re: Lua trouble.

Code:
function Update(self)
   if self:IsPlayerControlled() == true then
      TimerMan.TimeScale = 0.1;
   else
      TimerMan.TimeScale = 1;
   end
end


Right, this should work.

IsPlayerControlled is a function with no arguments (arguments go inside parentheses). Since it's a function attached to self, you use a colon, not a period. Periods are for attributes, ie timerman's timescale.

You don't need semicolons at the end of logic statements, only things like TimerMan.TimeScale.

If then else elseif end. That's the chain for if statements; if and else should be tabbed to the same line for syntax, and end should also be at the same level. Then you need an end for the function itself (function update self).

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/