typedefs in ash

So: on a wild guess I tried using typedef in ash, and lo and behold! typedefs exist.

However, I am having a little trouble working with them according to my C/C++ typedef background knowledge. I'm not sure if this is a Mafia bug or just my lack of understanding as to how they work in Mafia, so I figured I'd ask around for insights rather than filing a bug report.

Simple example:
Code:
typedef int foo;
foo x = 0;
gives me the error message "Internal error: Cannot assign int to foo"

A slightly different assignment:
Code:
typedef int foo;
foo x;
x = 0;
prints a debug log, which I've attached.

Is there any way to assign a value to a variable of typedef'd type? These seemed reasonable tries, but it's quite possible I'm missing something.

A more complicated example:
Code:
typedef int foo;

record bar
{ foo member; };

bar b;

string [foo] baz;

baz[b.member] = "blah";
gives me the error message "Index for 'baz' has wrong data type (expected foo, got int)"

So even though I can't assign ints to foos, sometimes Mafia thinks that foos are ints anyway. What am I doing wrong here?

If anyone knowledgeable about ash typedefs could help me out, that would be awesome.
 

Attachments

  • DEBUG_20100129.txt
    1.7 KB · Views: 37
Last edited:

Veracity

Developer
Staff member
You found three bugs, which I have fixed in Revision 8035.

Typedefs are a little-used feature which were (mostly) intended to let you alias aggregate types - maps and records. Perhaps I should have tested with aliases for ints, eh? ;)

By all means - use typedefs the way you think you should be able to use them and continue to report bugs if they don't work the way you expect.
 

zarqon

Well-known member
Oooh this is excellent. I have lots of float[element] in my combat script which I'd wished I could define as a type. Thanks for this, both of you!
 

Veracity

Developer
Staff member
Interestingly, those would have worked before; when I implemented it originally, I tested with maps. aqualectrix just found that "simple" types could not be typedef'd reliably.

Well, now it looks like I will have two script writers to shake out bugs in this feature. ;)
 
Top