Displaying variables

Post Reply
User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Displaying variables

Post by Vadi »

The only thing missing for the 1.0 release, for me personally, is variable display. Some people even think Mudlet doesn't have variables because they don't see a button for them :?

I think that the solution to this should come in two steps, the "easy to implement" one and a "fully-featured" one.

The first one would simply display all global variables, and have no auto-update - instead just have a "refresh" button to reload all values. It wouldn't allow you to edit the variables, either (you'd do that via scripting as before). So something like a two-column table, with a column for the variable name and value, would go. The only stumbling point here is how to display tables - which can also be nested. The only idea I have is to simply represent its value in text format, which won't exactly be pretty :|

For a fully-featured one, it would have an auto-updating feature. This is possible through the use of metatables - you can call a function when a specific variable was changed and update it in the gui. To keep things efficient (and not slow down when there are a lot of variable changes and you got the script editor open), perhaps the updating could be done on a tick - every 50ms or so should be plenty. Though that's just theory for now, haven't tested the performance of that yet.

Does anyone have an idea on how to represent tables in a gui though? Speaking of which I wonder how do other clients represent them.

derekperrault
Posts: 14
Joined: Sun May 31, 2009 7:40 am

Re: Displaying variables

Post by derekperrault »

I think Cmud provides a list display using only a two column table. The problem with trying to generalize this could result in tables of tables... the interface would look too ugly.

Why not just run a "pretty printer" on the variable contents? That seems like it'd work out just fine to me. People using tables will still need to be able to code with all the Lua syntax in the alias/trigger interfaces, so why try to dumb it down in the variable display?

Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

Re: Displaying variables

Post by Caled »

Is this even necessary in the script editor? I agree that a list of global vars and their contents might be nice, but tables - not such a big deal. They can be displayed in the main window and this is acceptable since we use a lot less tables than other variable types.

Note that I'm not saying we use tables less, but that we use less of them, and when we do, it is usually difficult to just 'forget' about them.

With normal variables, being able to scan through a big list of them to see if the one you want exists and has a value could be useful when debugging scripts. With lists, be it afflictions, enemies etc - generally I would already have an alias which calls a function to display its contents.

One thing that might be nice, is if the display of variables also says what type the value is: string, number or some other. A common fault in my scripting tends to be values that are clearly a number, being interpreted as a string. The solution is to use tonumber() or tostring(), but discovering if that is actually the fault is a tricky process, usually involving having to put those above functions in random places by trial-and-error until the script starts to work.

Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

Re: Displaying variables

Post by Caled »

Oh, regarding the column display of lists and tables by CMUD.

For a nested table, it will show:

key1 val1
key2 val2|val2a|val2b
key3 val3

I'm not sure how it looks if you have more levels of nesting. I'll check it out later and post a screenshot if it is any good.

Ryan
Posts: 10
Joined: Mon Jun 22, 2009 1:15 am

Re: Displaying variables

Post by Ryan »

Actually, nearly all my useful variables are tables. I only have a handful of global variables that aren't tables, and most of those are ones I'll never need to think about again.

A bunch of my most important tables are tables of booleans or nested tables, so printTable was basically useless. I finally got fed up enough to code my own replacement, and I'm fairly happy with it. Here's an example of how it looks for an arbitrary complex table:

Code: Select all

table {
  1: 'first'
  2: true
  3: false
  'key1': table {
    1: 'You see exits leading north and south.'
    2: 'exits'
    3: 'leading '
    4: 'north and '
    5: 'north'
    6: 'south'
    'full table': table {
      'a': 1
      'c': 3
      'b': 2
    }
    'blank table': table {}
  }
  'key2': 256
}
I'd be happy with displaying tables like that, although of course it would need a full textbox, not just a simple two-column table.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Displaying variables

Post by Heiko »

Ryan wrote:A bunch of my most important tables are tables of booleans or nested tables, so printTable was basically useless. I finally got fed up enough to code my own replacement, and I'm fairly happy with it. Here's an example of how it looks for an arbitrary complex table:

Code: Select all

table {
  1: 'first'
  2: true
  3: false
  'key1': table {
    1: 'You see exits leading north and south.'
    2: 'exits'
    3: 'leading '
    4: 'north and '
    5: 'north'
    6: 'south'
    'full table': table {
      'a': 1
      'c': 3
      'b': 2
    }
    'blank table': table {}
  }
  'key2': 256
}
I'd be happy with displaying tables like that, although of course it would need a full textbox, not just a simple two-column table.
It would be nice if you contributed your code to make life easier for fellow users with similar problems. We are always looking for good Lua functions to expand our global Lua inherit in LuaGlobal.lua.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Displaying variables

Post by Vadi »

I thought about this and have a solution - treeviews are designed this. Think foldersin a filesystem.

Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

Re: Displaying variables

Post by Caled »

Ryan wrote:I'd be happy with displaying tables like that, although of course it would need a full textbox, not just a simple two-column table.
If you don't mind, could you please post your function that does this? I have a number of similarly complex tables and would really like to see them displayed like that.

Ryan
Posts: 10
Joined: Mon Jun 22, 2009 1:15 am

Re: Displaying variables

Post by Ryan »

Sorry, I had intended to post it as a package after cleaning the code up, but got distracted and forgot. Here it is!

And put my vote as a yes for treeviews. They're perfect.

Post Reply