PDA

View Full Version : I'd like more control over time in my scripts



LittleFlower
28th May 2004, 01:22 AM
I play all my FPS games with a joystick. Singleplayer and multiplayer. The game that I keep going back to is Unreal Tournament. A major part of UT is "dodging". This is where the programability of the CH Products joysticks come in very handy. I've spend quite some time to write a script that does *exactly* what I like. Dodging in UT is done by "doubleclicking" one of the WASD direction keys. My script is based emulating these keystrokes. One of the subtleties involved is the fact that the Unreal engine will only register a doubleclick of the WASD keys when the axis in that direction is not registering movement. So my script does something like:



if (JS1.B4) {
Â*compute into which direction the stick is pointing;
Â*if (dodging left) then
Â* Â*CMS.A1 = 128;
Â* Â*CMS.A2 = JS1.A2;
Â* Â*CMS.B111 = TRUE; Â* Â* Â* Â* // CMS.B111 emulates: KEYS +a -a +a -a
Â*else if (dodging right) then
Â* Â* Â*.... etc ....
endif


Because you can't dodge back to back, and because the axis during dodge influences how far you dodge, I want to keep control over CMS.A1 and CMS.A2 for about half a second after initiating the dodge. Now my big problem.

Whenever I try to do things in time, behaviour gets unpredictable. I read in the documentation that the TIMER function is doing stuff based on units of the time period for the character rate set in the GUI. I have set that rate to 25 milliseconds. Now I expect that the script runs every 25 ms. Is that true ? It sometimes seems that the script will only run when the input (axis or buttons) changes ? I also tried to do things like:



if (A100 > 0) then
Â*A100 = A100 - 1;
else
Â*// end of waiting period
Â*do something to finish action
endif

if (user did something) then
Â*start action;
Â*A100 = 20; // do something in 20 * 25 = 500 ms
endif


This should have the same result as using a TIMER(PERIOD, D1, 20) function, should it not ? In any case, when I use a similar construct, the resulting behaviour is unpredictable. Sometimes it works, sometimes it doesn't. E.g. when I play online, the renderer needs to display less frames, and therefor more CPU cycles should be available for other things like the joystick driver. However, against my expectation, it seems the control loop is running less often. I used a construct like "A100 = (JS1.A3 / 25);" so I could set the timer period based on the throttle, and do dynamic experimentation. The result was that under different circumstance, I can get the same behaviour by changing the timer period from 4 loops to 10 loops or viceversa. This all makes me believe that the control loop is run at random intervals, and not at exactly the 25 ms I have configured.

I would like to see a construct that allows us users to keep track of real time. Something similar to the TIMER commands, but where n is not loops, but milliseconds. It could be implement by a simple timestamp. You can set a timer for n milliseconds. And after n millisecond the timer becomes TRUE.



if (user does something) then
Â* initiate action;
Â* SETTIMER(T1, 100);
endif

if (T1) then
Â*finish action;
Â*T1 = FALSE; // Or UNSETTIMER(T1), or SETTIMER(T1, 0);
endif


Am I missing something ? Is there a construct already that does what I want ? If not, is there any chance my feature request will be implemented ? Thanks in advance,

Henk (aka LittleFlower).

MichaelCHProd
28th May 2004, 06:12 AM
oh boy :blink: .... Bob?

Bob Church
28th May 2004, 08:52 AM
Well, I can answer at least part of it. No, the script doesn't execute only on the clock. Timers and things in the script are sync'd with the clock, but the script itself can execute for several reasons. See the CMS Programmers Guide, look at the section on Predefined Variables and Constants for info on the CLOCKTICKED variable.

I don't think there is a useful way to speed things up beyond 25 ms, really. You run into problems with the system timers and keys start sticking stuck. XP would let it go down to 10 ms, but at 10 ms you'd have to hold better than 100 FPS to guarantee that keys were seen. I'll look at it, but I doubt that it would be any practical help. Is there any other way to do what you want?

- Bob

The StickWorks
http://www.stickworks.com

LittleFlower
28th May 2004, 05:31 PM
See the CMS Programmers Guide, look at the section on Predefined Variables and Constants for info on the CLOCKTICKED variable.[/b]

I have looked through the guide many times. :P I thought I had done some testing with the CLOCKTICKED variable. But I probably didn't. I was under the impression that the script didn't run often enough, so ignoring some control loop runs would even make it worse. I now change my mind, and it seems the control loop runs more often than I expected ! In any case, fyi the manual talks about (just like you) the "CLOCKTICKED" variable. In fact, in my control manager the variable turns out to be called "CLOCKTICK" !


I don't think there is a useful way to speed things up beyond 25 ms, really.[/b]

I'm sorry if my question was too vague. I don't want smaller or finer granualarity. 25 ms for keypress events, and 100 ms for my script seems to be good enough. I wanted to have a better idea about how much real time was between runs of the control loop.

I now used the CLOCKTICK variable to keep track of time myself. This seems to be good enough for what I want !!! My script now does what I want. Thanks for reminding me of the CLOCKTICK variable.

Bob Church
29th May 2004, 12:27 AM
>> In fact, in my control manager the variable turns out to be called "CLOCKTICK" ! <<

Mine, too. That&#39;ll teach me to believe my own babblings. :) You&#39;re right. I fixed the reference in the Users&#39; Guide, it&#39;ll be okay at the next update.

>> Thanks for reminding me of the CLOCKTICK variable. <<

You&#39;re welcome! I&#39;m glad it was some help!

- Bob

The StickWorks
http://www.stickworks.com