Page 1 of 1
RPMDelta not working?
Posted: Fri Sep 03, 2010 3:20 pm
by sanyix
function Update (time)
rpm_change = Call( "*:GetControlValue", "RPMDelta", 0 )
if ( rpm_change > 0.001 ) then
Call("M62surge:SetEmitterActive",1);
--else
--Call("M62surge:SetEmitterActive",0);
end
end
But but the rpmdelta never activates the emitter, while in same time with same call the engine start activates the emitter.
On control value dialog i see that the rpmdelta changing but still not activates the emitter.
I really have no idea why.
Re: RPMDelta not working?
Posted: Fri Sep 03, 2010 5:42 pm
by karma99
sanyix wrote:function Update (time)
rpm_change = Call( "*:GetControlValue", "RPMDelta", 0 )
if ( rpm_change > 0.001 ) then
Call("M62surge:SetEmitterActive",1);
--else
--Call("M62surge:SetEmitterActive",0);
end
end
But but the rpmdelta never activates the emitter, while in same time with same call the engine start activates the emitter.
On control value dialog i see that the rpmdelta changing but still not activates the emitter.
I really have no idea why.
Pretty sure you need to lose the brackets around the if
I did the EXACT same thing 2 days ago... switching the brain from daytime C# to night time lua is a constant pain!
if rpm_change > 0.001 then
Call("M62surge:SetEmitterActive",1);
--else
--Call("M62surge:SetEmitterActive",0);
end
Re: RPMDelta not working?
Posted: Fri Sep 03, 2010 6:40 pm
by scefhwil
From my playing around with lua scripts I recon that GetControlValue only has access to controls that are defined in the engine blueprint. RPMDelta seems to be an audio system only control that is only accessible to audio control blueprints.
To do what you want you will have to create your own rpmdelta using Call( "*:GetControlValue", "RPM", 0 ) and comparing old to new values over the time interval.
Stuart
Re: RPMDelta not working?
Posted: Fri Sep 03, 2010 8:18 pm
by sanyix
Rpmdelta is working in scripts, just the rw lua compiler have very strange behaviors. I did some emitter changes in oncontrolvaluechange function. And other ones in update function. The funny is, i you don't call beginupdate in initialise, then the update wont update. But if you do then in oncontrolvaluechange you wont be able to manipulate the emitters (simply the code there stops working).
And other strange thing:
regulator= Call( "*:GetControlValue", "Regulator", 0 )
delta= Call( "*:GetControlValue", "RPMDelta", 0 )
engsta= Call( "*:GetControlValue", "EngineStart",0)
if ((delta > 0) or ((0.1<engsta) and (engsta<0.9))) then
Call("M62surge:SetEmitterActive",1);
else
Call("M62surge:SetEmitterActive",0);
end
this is working correctly
if i change the if statement to if ((delta > 0) or (0.1<engsta<0.9)) the luac parser says ok.
But this if will be always true if once the delta > 0 (even if it isn't), and in same time the enginestart isn't changed.
But if i seperate the ifs to:
if ((delta > 0)....
end
if (0.1<engsta<0.9) ....
end
then the second if will be always FALSE, and the luac parser says OK again
After this i've used that statement above, but STILL didn't worked, when the luac parser said the syntax is correct. Then suddenly after some retries it worked...
BTW where is the documentation of the setemitter calls from the rw wiki?

(i've read this in another script) maybe rw have a lots of good things, but noone knows about it because it's undocumented...
Re: RPMDelta not working?
Posted: Fri Sep 03, 2010 8:38 pm
by sanyix
karma99 wrote:Pretty sure you need to lose the brackets around the if
I did the EXACT same thing 2 days ago... switching the brain from daytime C# to night time lua is a constant pain!
same here, but i'm JAVA programmer

Those brackets can make issues like this? That would be funny since i've never seen such issues in pascal, java, c#, js or php.
Re: RPMDelta not working?
Posted: Sun Sep 05, 2010 5:03 pm
by sanyix
Is there any usermade lua callable thing reference for rw? The rswiki "reference" is very incomplete...
Re: RPMDelta not working?
Posted: Sun Sep 05, 2010 5:36 pm
by AndiS
No reference here either.
But I would put all the GetControlValue into OnControlValueChange -- in doubt.
I am pretty sure that the () are not the real problem. But some place in the documentation says that you need double parentheses for the Print call, and I vaguely remember having a problem with this call and only one layer of parentheses. So I don't make any assumptions about the RW implementation of Lua any more.
And I would not waste time with (0.1<engsta<0.9) but stick with (0.1<engsta) and (engsta<0.9), just to make life simpler.
Re: RPMDelta not working?
Posted: Sun Sep 05, 2010 8:45 pm
by davveb
RPMDelta works fine in RailWorks script. I can't remember how off the top of my head, and I'm not on my gaming computer at the moment, but have a look at the scripts for the RW GP7 or the HST update I did. I used RPM_Delta to trigger the exhaust "surge".
Re: RPMDelta not working?
Posted: Mon Sep 06, 2010 2:29 pm
by sanyix
if name=="RPM" then
if ((50<value) and (value<350)) then
please someone tell me, me how can the 2nd if can be true, from 1 rpm to infinty, but not from 400 rpm to 0rpm?
Re: RPMDelta not working?
Posted: Mon Sep 06, 2010 2:55 pm
by AndiS
In my view, it would be true for just above 50 to just below 350, not 0, not 400, etc.
Must likely, something in another place of the script went wrong, if you see something happening with 400 rpm.
The above case is one where you can perfectly go without all the (). I said that I don't think they harm, but I also say that I don't make any permanent assumptions any more. But I have no idea how parentheses can make this statement to evaluate to true for some other range of values.
Re: RPMDelta not working?
Posted: Mon Sep 06, 2010 3:40 pm
by sanyix
AndiS wrote:In my view, it would be true for just above 50 to just below 350, not 0, not 400, etc.
Must likely, something in another place of the script went wrong, if you see something happening with 400 rpm.
Yes that would be the correct but not that happens. The value and name directly taken from OnControlValueChange.
The strangest thing, this activated just when the rpm is rising, and never when falling.
Maybe the lua is working with not real numbers, but numbers from the 5. dimension?

)
Or just the OnControlValueChange event is bugged in rw, and not working as it should.
Anyway i can't even debug it, because if i set the logmate filter to "all", the game freezes after some seconds when the log spam comes, and the "Script Manager" filter doesn't work.