Records without a name and temp records

Fluxxdog

Active member
So I found something nice and interesting... records don't quite need names.
Code:
record my_rec_name{
   item whatever;
   int something;};
my_rec_name [int] map_name;
This is the way I've been doing it. I've found that most of my cases, I only use the record's name two times in my scripts, once when I define it and once when I create the map. I've found through some experimenting you can write like this:
Code:
record {
   item whatever;
   int something;} [int] map_name;
You define a map of records. Now, the record isn't completely nameless, it just has an internal name generated for it (as determined in Parser.java). But I haven't found a way to reference it after that. For a record definition that you're not going to use with anything else, this can be handy.

Another interesting kicker I found is that you can define a record as part of a function. Try this on for size:
Code:
record item_list{int num; item itm;} [int] item_stuff(){ item_list [int] i_l;
	i_l[0].num=1;
	i_l[0].itm=$item[pail];
	return i_l;
}

print(item_list()[0].num+":"+item_list()[0].itm);
The catch with this is, as far as I've experimented, you need to name the record so you can store values to a map. You can cut item_list from the record definiton, but there's not way to reference it when you build your map. I've found that it gets a name of "anonymous record xxxxxxx" where xxxxxxx is a hexidecimal string.

Anyway, played with it and thought I'd share my findings in case it helps anyone. Have fun!
 
Top