View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:06 pm



Reply to topic  [ 7 posts ] 
 Lua trouble. 
Author Message
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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.


Last edited by CrazyMLC on Sun May 17, 2009 7:22 am, edited 1 time in total.



Sun May 17, 2009 6:38 am
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Sun May 17, 2009 6:50 am
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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.


Sun May 17, 2009 7:15 am
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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


Sun May 17, 2009 7:58 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Sun May 17, 2009 11:45 pm
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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.


Sun May 17, 2009 11:48 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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).


Mon May 18, 2009 12:14 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.061s | 15 Queries | GZIP : Off ]