View unanswered posts | View active topics It is currently Sat Apr 27, 2024 12:55 pm



Reply to topic  [ 9 posts ] 
 Oh look! Another Lua topic because I can't solve lua myself 
Author Message
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post Oh look! Another Lua topic because I can't solve lua myself
Wow, I need to really solve this myself, but i can't. I want speed to continually increase, but for some reason I don't think it's working.

Code:

Code:
function Create(self)
self.ToDelete = false;
self.timerl = Timer();
end
function Update(self)
   local speed = 1.0
   if self.timerl:IsPastRealMS(50) then
      speed = speed * 1.1
      self.timerl:Reset();
   end
end

My goal is to continually increase "speed". I don't think it is, but i could be wrong.


Fri Jul 03, 2009 7:46 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Oh look! Another Lua topic because I can't solve lua myself
That's because every update you are defining the speed as 1.0.


Fri Jul 03, 2009 7:56 pm
Profile WWW
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post Re: Oh look! Another Lua topic because I can't solve lua myself
zalo wrote:
That's because every update you are defining the speed as 1.0.


So how would you make it to update "speed" every time the timer is past whatever MS? Better yet, how would you get it to even work?


Fri Jul 03, 2009 7:59 pm
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: Oh my! Another Lua topic
What Zalo said. Also, what is speed supposed to do?


Fri Jul 03, 2009 8:05 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post Re: Oh my! Another Lua topic
piipu wrote:
What Zalo said. Also, what is speed supposed to do?


Just a variable I'm gonna use in a code. So how will i get it to work in multiplying it by 1.1 every 50 MS?


Fri Jul 03, 2009 8:06 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Oh look! Another Lua topic because I can't solve lua myself
Global variable or not?
If it's just for it's self, then:
Code:
function Create(self)
self.ToDelete = false;
self.timerl = Timer();
self.speed = 1.0
end
function Update(self)
   if self.timerl:IsPastRealMS(50) then
      self.speed = self.speed * 1.1
      self.timerl:Reset();
   end
end

If it's global, I need the code for both objects, and the preset and class names.


Fri Jul 03, 2009 8:31 pm
Profile
Banned
User avatar

Joined: Tue Feb 27, 2007 4:05 pm
Posts: 2527
Reply with quote
Post Re: Oh look! Another Lua topic because I can't solve lua myself
I guess these guys aren't explaining the problem to you adequately.

The issue is that when you call your function, one of the first things that it does is set the property "speed" to 1.0. Every time you call that function, speed becomes "1.0," regardless of its previous attribute.

What mail just suggested was that the property becomes a global (read: public) property and is set to 1.0 before the execution of the function.

Does that make sense?

also, use
Code:
self.speed *= 1.1


Fri Jul 03, 2009 9:14 pm
Profile YIM
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post Re: Oh look! Another Lua topic because I can't solve lua myself
Oh. Okay, thanks :) But what if I put a like

Code:
local speed = 1.0
in create? Would that still set it to 1.0 every sim update? Just curious.


Sat Jul 04, 2009 1:14 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Oh look! Another Lua topic because I can't solve lua myself
function Create(self)

runs when the particle in question is created (imagine that)

function Update(self)

runs the full script every sim update frame

function Destroy(self)

runs when the particle in question is destroyed

if you define the variable in create, you're then allowed to reference and use it properly in update. in this case, since it's defined in create, you can do all your multiplication in update and it'll work a-ok

ps, there's no *=,+=, etc, lua's weird that way.


Sat Jul 04, 2009 1:43 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.733s | 17 Queries | GZIP : Off ]