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


Joined: 27 Jul 2004
Posts: 25

PostPosted: Sun Feb 26, 2017 4:32 am   

Saving literal evaluations of functions at menu creation?
 
So, populating a menu like this:

Code:

counter = 1
#SORT planets

#WHILE (@counter <> %numitems(@Planets)) {

#SAY Adding %concat("'",%item(Planets,@counter),"'") to Calc Menu.

temp = %concat("@",%string(%item(Planets,@counter)));#SA @temp
temp_name = %string(%item(Planets,@counter))

#MENU @temp_name {

$s = %db(@temp,starsystem);#SA $s //Needs to eval on #MENU Command, not save literally for future eval.
$x = %db(@temp,x);#SA $x //Needs to eval on #MENU Command, not save literally for future eval.
$y = %db(@temp,y);#SA $y //Needs to eval on #MENU Command, not save literally for future eval.
$z = %db(@temp,z);#SA $z //Needs to eval on #MENU Command, not save literally for future eval.

$x0 = $x + @BaseCalcOffset;#SA $x0
$x1 = $x + @BaseCalcOffset + @WingShipOffset;#SA $x1
$x2 = $x + @BaseCalcOffset - @WingShipOffset;#SA $x2

path_cockpit_to_nav

#IF (@battlegroupcommander = true) {
battlegroup nav '@wing1name' calculate '$s' $x1 $y $z
battlegroup nav '@wing2name' calculate '$s' $x2 $y $z
#SAY @wing1name calculating for: $s $x1 $y $z
#SAY @wing2name calculating for: $s $x2 $y $z}

calc '$s' $x0 $y $z
path_nav_to_cockpit

Destination = %item(Planets,@counter)
} calcmenu
#ADD counter 1
}
counter = 0


In the menu command, how can I save the @temp_name, %db(@temp,starsystem), %db(@temp,x), %db(@temp,y), and %db(@temp,z) literally?

I do not want them saved to the menu, rather evaluated at menu creation.

As it is currently, it creates the menu items, but only subs in whatever is currently in @temp, versus the one associated with that specific one.
Reply with quote
JRSteensen
Beginner


Joined: 27 Jul 2004
Posts: 25

PostPosted: Sun Feb 26, 2017 9:34 pm   
 
i.e. I'd want the expressions to evaluate at the time of the menu creation, versus having the evaluations placed inside the MENU command for future evaluation. Been banging my head on how to accomplish this.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Feb 27, 2017 4:06 pm   
 
I created some test data and things to make sure I got it right. In writing it I reordered some lines based on the probability that the Destination variable might need to be set for aliases called by the menu. I reversed the order of the counter and shifted things to local variables for execution speed. You should probably paste it into a blank session to make sure it is working as desired and then copy just the alias to your main session.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="test" copy="yes">
    <value>$counter = %numitems(@Planets)
#WHILE ($counter) {
 $temp_name = %item(@Planets,$counter)
 #SAY Adding '$temp_name' to Calc Menu.
 $temp = %eval(%concat("@",$temp_name));#SAY $temp_name info: $temp

 $menu_string=%concat("Destination = """, $temp_name, """",%cr)
 $menu_string=%concat($menu_string"$s = """, %db($temp,starsystem),""";#SA Star system: $s",%cr)
 $menu_string=%concat($menu_string, "$x = ", %db($temp,x), ";#SA x: $x",%cr)
 $menu_string=%concat($menu_string, "$y = ", %db($temp,y), ";#SA y: $y",%cr)
 $menu_string=%concat($menu_string, "$z = ", %db($temp,z), ";#SA z: $z",%cr)

 $menu_string=%concat($menu_string, "$x0 = $x + @BaseCalcOffset;#SA x0: $x0",%cr)
 $menu_string=%concat($menu_string, "$x1 = $x0 + @WingShipOffset;#SA x1: $x1",%cr)
 $menu_string=%concat($menu_string, "$x2 = $x0 - @WingShipOffset;#SA x2: $x2",%cr)

 $menu_string=%concat($menu_string, "path_cockpit_to_nav",%cr)

 $menu_string=%concat($menu_string, "#IF (@battlegroupcommander = true) {",%cr)
 $menu_string=%concat($menu_string, " battlegroup nav '@wing1name' calculate '$s' $x1 $y $z",%cr)
 $menu_string=%concat($menu_string, " battlegroup nav '@wing2name' calculate '$s' $x2 $y $z",%cr)
 $menu_string=%concat($menu_string, " #SAY @wing1name calculating for: $s $x1 $y $z",%cr)
 $menu_string=%concat($menu_string, " #SAY @wing2name calculating for: $s $x2 $y $z",%cr)
 $menu_string=%concat($menu_string, "}",%cr)

 $menu_string=%concat($menu_string, "calc '$s' $x0 $y $z",%cr)
 $menu_string=%concat($menu_string, "path_nav_to_cockpit",%cr)

 #CALL %session.MakeMenu($temp_name, $menu_string, "calcmenu")
 #ADD $counter -1
}</value>
  </alias>
  <class name="calcmenu" copy="yes">
    <var name="Destination" usedef="true" copy="yes"/>
  </class>
  <class name="PlanetData" copy="yes">
    <var name="Planets" type="StringList" sorted="1" copy="yes">
      <value>Planet1|Planet2|Vulcan</value>
      <json>["Planet1","Planet2","Vulcan"]</json>
    </var>
    <var name="Planet1" type="Record" copy="yes">
      <value>x=7|y=3|z=-1|starsystem=Magrethea</value>
      <json>{"starsystem":"Magrethea","z":-1,"y":3,"x":7}</json>
    </var>
    <var name="Planet2" type="Record" copy="yes">
      <value>x=8|y=4|z=2|starsystem=Alpha Centauri</value>
      <json>{"starsystem":"Alpha Centauri","z":2,"y":4,"x":8}</json>
    </var>
    <var name="Vulcan" type="Record" copy="yes">
      <value>x=9|y=1|z=19|starsystem=Romulus</value>
      <json>{"starsystem":"Romulus","z":19,"y":1,"x":9}</json>
    </var>
  </class>
</cmud>
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
JRSteensen
Beginner


Joined: 27 Jul 2004
Posts: 25

PostPosted: Mon Feb 27, 2017 9:30 pm   
 
Works absolutely perfectly. Thank you.

Only minor issue is that it populates the calc menu in ascending alphabetical (Z->A) instead of descending (A->Z) order.

Fixed that with:

Code:

#WHILE ($counter) {
$temp_planets_list = %sort(@planets,1)
$temp_name = %item($temp_planets_list,$counter)


Thank you! Really do appreciate all the help recently!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Feb 27, 2017 11:08 pm   
 
The Planets variable is a permanent list variable. You set its sorting order directly in its settings and that will eliminate the need to play with the sort whenever you execute the alias to rebuild the menu.

Also I see there is a comma missing in my original post at this line:
$menu_string=%concat($menu_string,"$s = """, %db($temp,starsystem),""";#SA Star system: $s",%cr)
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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