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


Joined: 18 Dec 2010
Posts: 17

PostPosted: Sun Dec 19, 2010 4:17 pm   

Using values in value name (headache)
 
First time poster here.
Could somebody point me to a guide, or explain to me how can I succesfully use some values in value name (hard to define a search for that),
i.e. what brackets to use and if it is possible at all.

For example I am trying to write a script, where for each current team member a gauge will be created with their name as caption, their HP as value and "protect <name>",
as command when pressed.

Got all member names written into string $team, separated with white space,

#GAUGE D0 %item(@T0,1) @hp0 7 3 Team green red white //for team leader since he was captured separatly
#loop %numwords($team) {#GAUGE D%i %item(@T%i, 1) @hp%i 7 3 Team green red white} // rest of team (using %item(@T%i, 1) to access proper declination for name, as the MUD is not English.

Atm it doesn't work at all, which bothers me because something as simple as

#var D%i something ,works quite well.

Optionally how can I define the positioning of the buttons with the same (probably with XML, but dont reall know how to do that)
And is there a way to use brackets to use %alarm(name) as gauge value (using #alarm {*1} {timer=%alarm(name)} - to update value right now)

Thanks
Reply with quote
khil
Beginner


Joined: 18 Dec 2010
Posts: 17

PostPosted: Sun Dec 19, 2010 4:54 pm   
 
Mhm... OK i attempted few more combinations and got the @{D%i} syntax myself Very Happy

Still, how can i define the button position, w/o resorting to #call %pref(DefaultButton, something) before the loop.
Reply with quote
shalimar
GURU


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

PostPosted: Mon Dec 20, 2010 3:08 am   
 
Buttons are almost always created via the GUI.
As such its not really good practice to create buttons willy-nilly in this manner.
I would suggest you figure out the max number of guages you will need and create/align them all up how you want.
Then make a stringlist of all the buttonID's for these guages.
Then use triggers and such to link players to the button via script:
Code:
#TR {(%w) joins the group} {
   $buttonIDs=teamGauge1|teamGuage2|etc
   #FORALL $buttonIDs {#IF (!%class(%i)) {
      #ADDKEY teammates {%1=%i}
      #T+ %i
      #BREAK
   }}
}
#TR {(%w) leaves the group} {
   $left=@{teammates.%1}
   #DELKEY teammates %1
   #T- $left
}

This way reuses the same buttons over and over instead of trying to create and destroy buttons ad nauseum.
_________________
Discord: Shalimarwildcat
Reply with quote
khil
Beginner


Joined: 18 Dec 2010
Posts: 17

PostPosted: Mon Dec 20, 2010 12:54 pm   
 
Thx, for the answer, but I am still looking to create buttons dynamically (call me stubborn)
The solution you have given is already in place. I was even thinking to do something in terms of assigning every button to a separate class (tedious I know),
to be able to make them appear in an exact number I want (atm i have set of 10 or 20 depending on team size)

I read help for the extended #button command script, used in import/export, but is it some old Zmud help, as I see it. All export import in CMUD seems to be XML based now.
If it still has some use could somebody paste an example of a gauge button save as #button (many many arguments, I have trouble getting it right).

How can i write a button directly in XML? :(

And again, why cant i use %alarm(time) as gauge value?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Dec 20, 2010 1:31 pm   
 
Don't try writing it directly in XML.

The #button command does not have all of the functionality available in the Package Editor. There are some things you simply cannot do with the #button command. What functionality exists in #button is documented in the help pages.
Reply with quote
khil
Beginner


Joined: 18 Dec 2010
Posts: 17

PostPosted: Mon Dec 20, 2010 2:18 pm   
 
Yeah, I am starting to see the limitations now. However i got quite far. Asked my friend to paste me some Zmud gauge export, and got to this
Code:
#loop %numitems($team) {
$caption=%item(@{D%i}, 1)
$pr=%item(@{D%i}, 2)
$hp="@{hp%1}"
$move=50+%i*50
#BUTTON D%i {$caption} {protect $pr)} {} {} {$hp} {} {} {Size} {50} {20} {Pos} {$move} {1} {11} {} {Gauge|12|7|3|2} {} {Butts} {Explore|Inset} {} {3}
}


The main problem is being unable to use $hp in gauge value name and $move to position them (I tried to go around the problem using all those localvars)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Dec 20, 2010 5:10 pm   
 
For the $hp, you have the %1 within the quotation marks, so it is not being expanded. Try this:
Code:
$hp = %concat("@hp",%1)

For the $move, you are not performing a mathematical calculation. Enclosing it within parentheses will cause it to be a mathematical calculation. Try:
Code:
$move = (50+(%i * 50))
Reply with quote
khil
Beginner


Joined: 18 Dec 2010
Posts: 17

PostPosted: Mon Dec 20, 2010 7:07 pm   
 
Thanks for the clarification, i was missing that!

But in this case, #button function will simply write $hp or $move in the value box, not its actual value. Also i doesnt parse the %i from loop well either.
For $team consisting of 3 players, the result are 3 buttons with Name1|Name2|Name3 as caption each.
I am close to give up on that, unless somebody tells me how to obtain a zscript export of existing gauge, to reverse engineer it, but considering above failures in parsing i doubt.

Little request, could we have a little extra argument for %btnenable to make it disabled (disappear), besides disactivating it.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Dec 20, 2010 7:38 pm   
 
For your little request, all you need to do is use #T- buttonid (and #T+ buttonid) to remove (or return) the button from the screen.

For the other problem, you might be able to use #EXEC to run the button command with parsing. I haven't tried that. Otherwise, I think you are out of luck. The #BUTTON code has not been modified much since version 2, and simply does not understand many of the version 3 improvements to Cmud.
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