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
unrealtor
Beginner


Joined: 23 May 2020
Posts: 16

PostPosted: Fri Jun 05, 2020 2:27 am   

Button- Dynamic Caption
 
I am currently unable to get a button caption whose value is set to a variable, to dynamically bubble up. I have this working in zMud and it partially works in cMud (but only when the client is restarted or the button is saved and re-looks up the value, does the displayed value change). This is a slightly more complex setup because the caption variable's value technically contained pointers to values in a "Database Record" variable. Let me give an example below:

// set up the partyDB "db" variable with the keys as the member's names and a hit counter for the value
@partyDB = {"John"=12, "Jane"=27}

//value below gets set by a party script that builds the partyDB hash and then sets this value
@cap = @partyDB.John"-"@partyDB.Jane
//sample display: 12-27

//create the button (its a button because when pressed it will parse and send the results as a game chat, which works fine)
ButtonA.caption=@cap

So to summarize, in zMud whenever one of the values in the @partyDB was changed it instantly/dynamically displayed the change in the button's caption. However in cMud, when the values in @partyDB change, the output of the button's caption doesn't get updated.

Any thoughts on how I might be able to get this working properly in cMud?
Thanks!
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Fri Jun 05, 2020 11:07 am   
 
Button captions dependant on variables need a static variable.
If the value is stored in a dbVar the caption will not update properly.

zMUD does not have or use dbVars.
_________________
Discord: Shalimarwildcat
Reply with quote
chaossdragon
Apprentice


Joined: 09 Apr 2008
Posts: 167

PostPosted: Fri Jun 05, 2020 1:49 pm   
 
That seems weird then cause I use buttons well technically gauges to track in-combat [ hp/maxhp ] [ sp/maxsp ] [ targethp ] etc... including xp and money below is my caption using dbVar which updates no problem.
Code:

[  Exp: %format("&10.0n",@FishSpeakerData.totalExp)   /  Exp Cap: %format("&10.0n",@FishSpeakerData.expCap)  ] | [  Solaris :%format("&10.0n",@FishSpeakerData.totalSolaris)   /   Bank :%format("&10.0n",@FishSpeakerData.bankedSolaris)  ]


but each gauge has a button function on click.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Fri Jun 05, 2020 2:02 pm   
 
It might be a result of being nested in a %function then, I often have to do that to force evaluation of %concat'ed variable names.
Try using %db(@var, "key")
_________________
Discord: Shalimarwildcat
Reply with quote
unrealtor
Beginner


Joined: 23 May 2020
Posts: 16

PostPosted: Mon Jun 08, 2020 7:43 pm   
 
In zMud it's using %db(@var, key) which I originally tried and then over to the newer name-spacing; neither of which works. I tried setting the button's caption to a function that returns the value of the variable with with data I want in the caption; but still when the backing "db" data gets updated, the displayed caption doesn't change. Even tried using %eval() around things just to see, again no dice. I probably can forcibly change the button's caption directly, but zMud's bubble-up ability is more elegant (not requiring extra parsing). I can't think of or find any other options to try.

I did just find the following blurb under the help "makebutton":
"Some properties can be set by the index (position in the table), while other properties can be set by name.
The indexed properties are: Caption, Value/Script, Class, and Name/ID."

So it seems that with the change to Lua and the statement that it indexes the Caption, maybe this ability was lost with the indexing process/needs. (IE: It displays the internally indexed value, which likely only changes with a save/update/reload type command, which is what I have experienced when seeing it actually change).

I did find that maybe I could call the update method as follows:
endupdate()
tells CMUD that the Lua script is done changing the object and it should be refreshed within the CMUD user interface.

I can't figure out how to call the button in my tests to see if that function will do the trick. Let say I have given it the id of "testBtn", what is the correct syntax for this sample?: #exec testBtn.endupdate()

Much thanks!
Reply with quote
unrealtor
Beginner


Joined: 23 May 2020
Posts: 16

PostPosted: Wed Jun 10, 2020 7:16 pm   
 
Well, I figured out a workaround that doesn't feel too painful. I had to use a second var to hold the dynamic content and then when the trigger fires off that adds to the db, it sets the var tied to the caption with the temp var; which in the process is interned into a literal string. Here is a sample for any others who may want to do this:

@partyDB = {"John"=12, "Jane"=27}
@capTmp = %db(@partyDB, John)~%db( @partyDB, Jane)

ButtonA.caption=@cap
//a trigger fires off, updating a @partyDB.John to +1: below is at the end of the trigger
@cap = @capTmp //value stored in @cap: 13~27
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