Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
dak
Beginner


Joined: 08 Aug 2009
Posts: 14

PostPosted: Sat Aug 08, 2009 8:36 am   

Help: Lua and Buttons
 
I'd like to take advantage of some of the advantages Lua has over zScript, although I'm running into some obstacles when trying to manipulate buttons using Lua.

Issue #1: Captions
From what I can tell, there's no way to use Lua in a caption. For example, I might have a button caption that looks like this:
Code:
Time Tracker: %format( 0, %eval( (%ctime-%float(@time_variable)) / 60))

This will make the buttons caption appear to be something like: "Time Tracker: 30" if it was started 30 minutes ago.
I'd like to do this same thing, except using a lua script, or at least a lua variable.
I suppose worse case scenario is I would have to update a lua variable and a zscript variable any time the variable changed.

The second issue I have with captions is that I sometimes would like them to change completely. For example, rather than showing the above caption, sometimes it might show a single word, like "Off".

I know I could set the caption to a variable and have the variable change between the time code and "Off", but then the variable doesn't update cleanly... it has to be manually updated in order to update the time. For example, if I set the caption to @caption_variable and say:
Code:
caption_variable = %string( "Time Tracker:" %format( 0, %eval( (%ctime-%float(@time_variable)) / 60)) )

Then the variable simply becomes "Time Tracker: 30" rather than the formula, and so will only update to the new time when updated in a new script.

I would like to be able to set the caption to sometimes use the zScript (or Lua) script, and sometimes be set to a basic string.

Issue #2 Button Colors
There's a few issues within buttons here. The first is that I tried setting a button's color to that of another known button using something like the following:
Code:
#CALL %btncol( button1, %btncol(button2) )

Unfortunately, the integer returned by %btncol( button2 ) doesn't seem to be understood by the %btncol() function, which basically seems to always just turn the button white instead. The work around is extremely messy, for example:
Code:
#IF ( %btncol(button2) = 45824 ) {#CALL %btncol( button1, black, green )}

This is repeated for every single possible color.

Ideally, either the code I originally tried would work, or a separate function would exist to get the background and foreground colors from a button, which could then be passed to btncol(), for example:
Code:
#CALL %btncol( button1, %btntextcol(button2), %btnbackcol(button 2) )

Assuming the above functions existed/worked, then doing this in Lua as well shouldn't be an issue.

Issue #3 Aliases
I'm being a bit lazy here since I haven't tested this thoroughly myself, but since I already asked the above two questions, I thought I'd toss it in.

I didn't see any documentation regarding calling an alias using Lua. I assume the syntax would be:
Code:
zs.alias( alias_name, argument )

or, if no argument is passed:
Code:
zs.alias( alias_name )

but, can anyone confirm/deny and maybe provide an accurate example if the above is incorrect?
Reply with quote
dak
Beginner


Joined: 08 Aug 2009
Posts: 14

PostPosted: Sat Aug 08, 2009 3:45 pm   
 
Well, I've managed to answer my own question with regard to aliases and lua:
Code:
zs.execalias("test",123)

Code:
zs.execalias("test")

And it is in the documentation, I just apparently missed it.

However, issues with manipulating buttons and colors remain, and are kind of forcing me to use zScript (and in some cases use some really ugly code).

I'm also unable to get the following code to work (I've only tried from the command line):
Code:
#LUA zs.cmd.call( "%btncol( button_name, black, green )" )
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Aug 10, 2009 3:18 am   
 
You can accomplish the same thing with

Code:
zs.getbutton('foo').color=1291283
zs.getbutton('foo').textcol=921821


You'll have to convert the hex value of the color you want to a numeric.
_________________
Asati di tempari!
Reply with quote
dak
Beginner


Joined: 08 Aug 2009
Posts: 14

PostPosted: Mon Aug 10, 2009 8:39 am   
 
Tech wrote:
You can accomplish the same thing with

Code:
zs.getbutton('foo').oncol=1291283
zs.getbutton('foo').textcol=921821


You'll have to convert the hex value of the color you want to a numeric.


And how would you then go in reverse and set a button to the new desired color? It seems like the answer should be obvious, but for some reason it's not coming to me.

Thanks for the response.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Aug 10, 2009 2:13 pm   
 
You can get a reference to the button object using zs.getbutton. In my my example, the id of the button is 'foo'. If you want to set the button's color you set the 'oncol' property. If you want to set the color of the text of the button, i.e. it's caption, you set the 'textcol' property.

The numbers I include in my example almost certain don't match up to black and green. I typed them randomly, the idea was to show an example of how you set the color code you want. The numerical value for black is 0. For green is 65280.

[Edit]I made a correction here. To set the button color in the Public i.e. 2.37 version of CMUD you would use the property 'oncol' not 'color', as I stated previously. I've edited my original post to reflect this.
_________________
Asati di tempari!
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Fri Oct 07, 2011 9:06 pm   
 
The help files are incorrect.

The oncol and offcol properties do not exist as of 3.34 and you get an error if you try to set them stating such. The only way to set the color is through the zs.getbutton("btnID").color property, which means you have to update it each time. It also seems to me like push buttons and toggle buttons are getting confused in the help file because push buttons don't normally have a second state. It should be EASY to set up buttons in Lua with access to the properties like this, but the problem is the help files are missing or misinforming.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Fri Oct 07, 2011 9:10 pm   
 
Tech wrote:
You can accomplish the same thing with

Code:
zs.getbutton('foo').color=1291283
zs.getbutton('foo').textcol=921821


You'll have to convert the hex value of the color you want to a numeric.


Code:
function GetBGR(color)
  return zs.func["colorname"](color)
end


Code:
zs.getbutton("foo").color = GetBGR("red")
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net