The online racing simulator
[Solved] Detect finish of Autocross layout?
Hello
Here is my first ever Lapper script:

CatchEvent OnLapperStart()
GlobalVar $finishers;
EndCatchEvent

CatchEvent OnResult( $userName,$flagConfirm )
# CatchEvent OnFinish($userName)
globalMsg ("Someone finished the race!");
$finishers = $finishers +1;
globalMsg ($finishers);
EndCatchEvent

It counts how many cars have finished a race.

Problem:
It only works on normal tracks.
On AX layouts nothing happens when the car crosses finish line.

In LFS race is finished, but in Lapper the OnResult() event is not triggerd. OnFinish() is not triggered either.
Is there a different event that has to be used?

The layout is just start-position, checkpoint, finishline, nothing special.

Ps:
In https://www.lfs.net/forum/thread/58433-Release it says "please read doc/readme.txt."
but in http://cgtavc.monespace.net/lapper/download/lapper/LFSLapper6.013b.zip there is no such file?
Here's Lapper 6.0.14, which was the last version released by Kravy.
I will look into your issue a little later on, have to do some other things first.

*edit* forum doesn't allow me to upload a 2 MB zip file, so I have put it on my own webserver.

http://sjoerd.rosdorff.dyndns.org/test/lapper_6014.zip
Yisc is the guy for helping you!

Surprised it works at all - normally you have to specify your GlobalVar.

Your code
CatchEvent OnLapperStart()
GlobalVar $finishers;
EndCatchEvent

Should define the Var value.
CatchEvent OnLapperStart()
GlobalVar $finishers;
$finishers=;
EndCatchEvent

So, its name of Var first, followed by same name with a value.

The most common GlobalVar's are usually specified by people for button properties, such as;

GlobalVar $MorigL; $MorigL = 86; # Left edge of main content window / button / label
GlobalVar $MorigT; $MorigT = 90; # Top edge of window / button / label
GlobalVar $MWidth; $MWidth = 20; # Width of Dialog box / window / button / label
GlobalVar $MHeight; $MHeight = 4; # ...height of row of text
GlobalVar $Mspacing; $Mspacing = 4; # ...height of spacing between text
GlobalVar $Mtime; $Mtime = -1; # display button for how many seconds (-1 = permanent)

Lapper doesn't care if you layout each Var on 1 line or 2, as long as Var

Name and Var value are both followed by a semi-colon.

GlobalVar $MHeight; $MHeight = 4; # ...height of row of text

or

GlobalVar $MHeight;
$MHeight = 4;

Quote from Gutholz :...please read doc/readme.txt.....there is no such file?

A lot of very useful information can be found in the doc folder, when you open zip file (bin, doc, spec, src).

A lot of coding help can be found in changes.txt, and various Vars, etc, can be found in Lapper Events.txt and playerVars.txt.
Pfew, this puzzle nearly drove me nuts, but I found the answer at last.
For some reason, Lapper isn't recognizing the finishline used in the editor and therefor the OnFinish and OnResult event aren't activated.
To work around that issue (only a Lapper dev could answer that) you can use the following event to emulate an action on the finishline:


CatchEvent OnSpbLast( $userName ) # Player event
cmdlfs ( "/msg ^7DEBUG 3" );
EndCatchEvent

That event is called when you cross the finishline on a homemade layout.
I hope that works for you, as I am not sure all you could need, would be possible in that event.
sinanju:
It worked so I just assumed uninitialized variables default to 0. Not sure if that was just luck.
With 'normal' languages would be easy to google, with this seems to require bit more searching to figure things out. Wink

Yisc:
Yup thanks, that works.

I found in playerInfo.txt that I can get the time on such AX-track with
GetCurrentPlayerVar( "LapTime" );

"LapTime" does not include the time-penality for hitting objects.
How to get that?
(There is "PenaltyNew", but always returns 0, unless time or DT penality is given.)
Hm, after wasting over half an hour with stuff like:
$bla [3] = 100;

vs

$bla[3] = 100;

Ya right

Is there an option for stricter checking of code? Like more warnings in console?
Personally, I use PSPad, which colours different parts of the code script to make it easier to see if there's a glaring error.

Use PSPad with lapper.ini (found HERE), which has been setup with colours for different syntax highlighters.



Won't help with your specific issue, though.
Attached images
PSPad.jpg
I am still not convinced that the reason I gave last night, is the exact cause of the Finish/Result events not working, since Lapper does put your best time in the database when you cross the finishline, so it does know when you have finished. Will look into it again probably tomorrow.
Yisc: thanks for looking into it. Still so far the OnSpbLast event seems to fit my needs. Smile

sinanju:
Synthax coloring would be nice too.
(it seems bit incomplete, at least the [ReservedWords] list is very short. In your screenshot only closePrivButton is marked, but other Lapper functions are not)

But I meant something like putting the error-messages from log\LFSLapper-ERR.log into console.
Or in general any setting/trick that might be helpful.
For now I just set the log file to autoreload on change in texteditor. (notepad++)

---

Think I will just post about my Lapper adventures. Smile
Idea is to make a rallye script thing. After each player has driven the stage, the next layout should get loaded. Then each player gets one try again. At end all stage times are added up and winner is declared.
Already working are changing layout and adding times. Still missing is everything else...will continue on weekend.


1)
An array with 3 entries:
$test[1]=100;
$test[2]=200;
$test[3]=300;

Why does this clear the whole array except [2] ?
$x = 666;
$test[2]=$x;

It only seems to happen when assigning variables to already filled entries.
With numeric constants like
$test[2]=666;
there is no such effect.
So I tried what happens with
$x = 666;
$test[2]=ToNum($x);

and that does not clear the table. Huh?

2)
Still looking for way to read the time-penality for knocking over cones.

3)
http://en.lfsmanual.net/wiki/Hosting#Commands_with_a_parameter_-_entry_screen_mode
Quote :/autox X :load autocross layout named X for this track

This did not work for me.
However /axload works, even when not in entry screen. Is /autox something different or is wiki wrong/outdated?

4)
When driving on same map (say "Blackwood Carpark" BL3) but with different AX layouts, the LFS results table makes no sense after layout change. Is there a way to clear it?
(One can just ignore it, but would be nicer...changing track back & forth like "BL3 - SO1 - BL3" is not so nice)
Concerning point 1 and 2, I know that arrays got broken at some point and I am not sure that got fixed in a Lapper release. So some things regarding arrays might not work or not as intended. I might be able to help some more with it, but that would be tomorrow then.

Concerning point 3, I think the LFS Wiki is outdated.
This is what I read in Commands.txt , which is found in your "docs" folder of your LFS installation:

Autocross layout commands:

/axlist X :get list of layouts for track X - e.g. AU1
/axload X :load layout X on host
/axsave X :save layout X on host
/axlaps X :set autocross number of laps
/axclear :clear layout

Concerning point 4, I noticed the same behavior last night, so I think that is some LFS issue. It seems to correct it self, when you end the race, load the layout again and then start the next race.
(I updated wiki, thanks for confirm)
With regards arrays, almost forgot another strange thing:


$test["one"]=100;
$test["two"]=200;
$test["three"]=300;

FOREACH( $myVar IN $test )
writeLine ($myVar["key"]);
ENDFOREACH

What will the keys be? (yes, I mean the keys not the values)
I expected:
one
two
three


But it is:
test,"one"
test,"two"
test,"three"


Bit strange that the array's name is attached to the key like that?
To get the "real" key I mess around with strings like:

$realKey = subStr ($myVar["key"], 6); # 6 because of 'test,' - removes name of array and comma
$realKey = subStr ($realKey, 0,strLen($realKey)-1); # remove " at end
writeLine ($realKey);

Maybe one could also use SplitToArray ($myVar["key"], ",") and then put all the sub-string strings together, but leave out the first one. Then one would to adjust the 6 based on length of array name.
But all a bit exotic strange just to loop through array Looking
This thread is closed

FGED GREDG RDFGDR GSFDG