The online racing simulator
CASE command in a button?
If it's possible, I'd like myself and users to be able to use CASE commands by clicking on a button, rather than typing.

So instead of typing something like "!lapperversion", you just click a button that reads 'Lapper Version'.

Less chance of forgetting exclamation mark and/or mispelling.

I've tried various things, but nothing has worked, or given an error message in the logs.

Things like;

Sub Version($text)
$text = "!ver";
EndSub

Sub Version($command)
$command = "!ver";
EndSub

I haven't made changes to lapper since V6.014, and I regret to say that my memory is failing me, and I'm even struggling to understand a lot of the code I've written for add-ons.

If it can be done, any help would be appreciated.
I think that this does the trick:


openPrivButton( "button_lapper_version",160,122,20,10,5,-1,32,"^8Lapper version",Button_lapper_version );

Sub Button_lapper_version ( $KeyFlags,$id )
lapperVersion();
EndSub

Seems I may have picked one of the worst CASE commands as an example.

Your code does work, but I think it does so because after trialing other commands then trawling through the docs, I found that 'lapperversion' is also a lapper Var and a lapper Function.

I tried with about half a dozen CASE commands, making buttons and pressing them. Anything that wasn't a Var or a Function (ie 'lapperversion') only gave errors.

I also tried making a private button, as I thought I could put in the text I want, but I've never coded one before, so likely my code for that is well wrong. It didn't even end up as an error.

My test script and error log attached.
Attached files
case_commands_test.txt - 2.8 KB - 130 views
127.0.0.1-29999-ERR-Log.txt - 1.5 KB - 119 views
I got all buttons you made working and attached a file with all those buttons.

- download the file and rename it to: var_button.lpr
- put it in your 'includes' folder
- add a line to file addonsused.lpr to point to the new file
- restart Lapper by typing: !reload

You can bring up the buttons using: !btntst
Attached files
var_buttons.txt - 2.9 KB - 147 views
Tried your script and works fine, although I'm trying to get everything, including Case commands, working with a button, and you want me to use a Case command to get things started Tilt

Anyway, looks like the proper answer is no to actually putting the Case command inside a button. You basically have to use LFS/Lapper/Player Vars to run the commands inside a button.

This is fine, now that I know this.

But many thanks for putting in the effort for me. It is appreciated, as I had a one track mind to use the actual Case commands (!track, etc).

Basically, (especially) because of mobile phone apps, people are more used to having to press something for things to happen, rather than type things in. Probably why emojis are doing well. It's the way I've been leaning for years, and this was really the final step.

Anyway, I made a button to start process off, and I've used your code to get things going.


If anyone's interested, I've included a txt file with your and my code as it stands.

Anyone that wants to use it, should know about changing .txt to .lpr, etc.

Clicking "Button Shortcuts", will close that button, and add panel with a choice of buttons that you need to click to give you specific information.

If you forget to close these buttons, then they will self close when you go back on track.
Attached images
lapper buttons.png
Attached files
case_commands_test.txt - 4.3 KB - 98 views
Case just means that several actions can be done within the same sub.
In this case (no pun intende) all commands starting with ! are handled in the OnMSO sub.
When text is !laps case X is excuted
When text is !ver case Y is executed
ect.
So Case and button won't go together, unless you have text button and want several actions in that particular sub.
Yes, I understand.

I had this idea that I would rather present drivers with a button than give them a list of commands that they type out themselves.

There's a lot of CASE commands within the default lfslapper.lpr file, and I thought that there could be a way for a button to call these commands through a press rather than typing.

It appears that there isn't. Which is fine, as your code allows me to make a button for at least some of these commands, using some of the standard Vars.

Since seeing your code, and using it to make buttons that trigger the response I want, I was going to just delete the CASE commands that the buttons have replaced, but as it's unlikely a lot of people who come on my server will know about these commands, I'm just going to leave them in.

I could just remove all the standard CASE commands, and my buttons, as the reality is, that drivers usually care about one of two things; where do they come in the TOP list and/or where do they come in the drift score list.

At the moment, I'm trying to work with !ver 7.080, but I've never used anything, or coded anything, since V6.014. The only people who will care, are lapper users who come on my server. Very small amount. And who cares what version of LFS I'm using? If people can get on the server (and it gives the details in the Server Master List when you go multiplayer) then that's enough.

My server will only be used for single lap hotlapping on layouts that I've designed and made, and the reality is, for that, I only want and need 5 things to work; A TOP list, a DRIFT TOP list, your great Pitboard (pared down as I only want to see times), my Drift Meter, and (for use only by myself) my distance meter, so I know how long a lap is, which I quote when I make my layouts public on this forum.

And none of these need CASE commands.
Just ask here if you run into any problems and/or have questions. It might bring you back up to speed, as a lot has changed in Lapper (and I am far behind the latest versions as some of my scripts did not work with the latest releases) over the years.

It might also help other Lapper users that are scared to ask for anything (mostly because most questions that have been asked, come from people that only 'demand' things while being unregistered to LFS) or are struggling with things them selfs or have ideas they cannot realise.

I won't go as far as coding all that's been asked for or debugging all code that will be presented here (learning to do things your self is the best way to improve your self), but putting someone on the right track isn't a problem for me and if something really interesting comes along, I am sure I will start my dev environment to try and tackle the issue / answer the question.

FGED GREDG RDFGDR GSFDG