Newsgroup: it.comp.giochi.avventure.testuali
Titolo: [inform] this is driving me crazy...

Hi, everybody,
I've got a stupid problem that's driving me crazy: I set up this little 
architecture to play sounds under glulx
[ Emit_soundSub number;
number = noun.filenumber;
print "DEBUG: Somebody generated a sound with 'emit_sound'... the 
parameter is ", (object) noun, "^";
print "DEBUG: The filenumber is ", number, "^";
	   ! now I have to play the right sound via glk
	   glk_schannel_play_ext(gg_soundchan, number, 1, 0);
	   AfterRoutines();
];
So I can define my sounds like
Object scream "scream"
	   with filenumber 1; ! sound file SND1.aif
and happily generate sounds within the code with a simple line like
<emit_sound scream>.
So far, so great; the problem is that now I'm trying to randomize the 
sounds played. Since I only need to work on integers it should be easy, 
right? But this doesn't work
Object sax_average "an average sax sound"
		with filenumber [; return random (24,25,26,27); ];
nor does this
Object sax_average "an average sax sound"
		with filenumber [; return 23 + random (4); ];
The debugging prints go like this: (the first one below is NOT random 
and works)
 >play kazoo
(first taking the blue plastic kazoo)
DEBUG: Somebody generated a sound with 'emit_sound'... the parameter is 
kazoo
DEBUG: The filenumber is 30
 >play sax
(first taking the old saxophone)
DEBUG: Somebody generated a sound with 'emit_sound'... the parameter is 
an average sax sound
DEBUG: The filenumber is 90466  <---------
Where does this damn number come from?!? It really beats me, I'm going 
crazy!
thanks to anyone helping me :)
ciao
S

                 with filenumber [; return random (24,25,26,27); ];
When you do this, sax.filenumber is a routine, so you're getting its
address, rather than running it.
You can do "number = ValueOrRun(noun, filenumber)" instead. This will
work for all routines, and numeric values up to 255. 
--Z
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
* Make your vote count. Get your vote counted.

 crazy!
The number is (roughly speaking) the address of the method's code.  The 
statement 'number = noun.filenumber;' simply copies a number from a 
property to a variable.  The statement 'number = noun.filenumber();' 
will call the method whose address is in a property and store the result 
in a variable.  What you probably want to do is this:
   if (metaclass(noun.filenumber) == Routine)
     number = noun.filenumber;
   else
     number = noun.filenumber();
BTW, metaclass isn't too smart.  It bases its decision on the value of 
the variable, so if, for example, filenumer were really set to a large 
value like 90466, then metaclass would think it a Routine.  This is 
important because small numbers (like 24) will return a metaclass of 
Object or Class.

 work for all routines, and numeric values up to 255. 
thanks. This works, of course... never heard of this function (and it's 
not in the DM4 either), I guess it just does more or less what Samwyse 
wrote in the second message (ie metaclass checking).
I should have understood what was going on (actually I went as far as 
guessing that the number was the sub address), the problem is that 
inform does the "return automagically a number or a function _result_" 
trick so often that I was expecting it here, too!
Plus, it was 3 AM :)
So, thanks a lot to Zarf and Sam, expect some heavy saxophone playing in 
my incoming IntroComp work (hum, it's due in about 8 hours... agh)
ciao
S

 trick so often that I was expecting it here, too!
Well, actually, if you code this:
   flag = obj.method();  ! note the parens, this is a function call
and obj.method is a string instead of a procedure, the Z-machine treats 
it as if you coded this:
   method [ ; "my string"; ]
Which will print the string and return true.  It's all detailed in 
chapter 5 of DM4.
But hey, I understand.  Inform has almost as many special features as Perl.

 chapter 5 of DM4.
heh, I guess I should give it another good read... it's been so many 
years   :)
ciao
S

 --Z
Quanto onore, Plotkin in persona qui su ICGAT, seppur in X-post....
Saluti,
Dott. Piergiorgio.

 Quanto onore, Plotkin in persona qui su ICGAT, seppur in X-post....
bello eh? Il post lo facciamo stampare su pergamena e incorniciare, 
magari... :)

 magari... :)
Non e' una cattiva idea :DDDD
Saluti,
Dott. Piergiorgio.