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
shalimar
GURU


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

PostPosted: Sat Feb 15, 2014 12:13 pm   

Sorting DBvar
 
A have a chart of items i have compiled with their various High and Low values marked out to form a range
I would like them displayed in ascending order, by @var.%i.Low and in the event of a tie, by @var.%i.High

I was using this to display at the moment

#FORALL %dbkeys(fishDiff) {#SAY {%format("&-25s &4d -&4d", %i, @fishDiff.%i.Low, @fishDiff.%i.High)}}
_________________
Discord: Shalimarwildcat
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sat Feb 15, 2014 9:00 pm   
 
If you don't mind using Lua:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="showfish" language="Lua">
    <value>local t = {}
for k, v in pairs(zs.var.fishDiff) do
  table.insert(t, {Key = k, Low = v.Low, High = v.High})
end
table.sort(t, function(a, b)
  if a.Low == b.Low then
    return a.High <= b.High
  else
    return a.Low <= b.Low
  end
end)
for i, v in ipairs(t) do
  print(string.format("%-25s %4d -%4d", v.Key, v.Low, v.High))
end</value>
  </alias>
</cmud>
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 15, 2014 9:13 pm   
 
File: . Line: 10 Col: 20 Error: Invalid element name: "
_________________
Discord: Shalimarwildcat
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sun Feb 16, 2014 6:54 pm   
 
Meh, copy/paste it into an alias manually. The forum breaks the xml parsing for < and >, I don't remember how to work around that offhand.
Reply with quote
shalimar
GURU


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

PostPosted: Mon Feb 17, 2014 7:32 am   
 
Attempt to index local 'b' (a nil value) (line 6)

Stack trace:
[string "code"]:6:in a Lua function
[C]:-1:in function "sort"
[string "code"]:5:in main chunk"
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 22, 2014 2:36 pm   
 
Ever figure out the error message so i can get this working?
I don't know lua.
_________________
Discord: Shalimarwildcat
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