My poor little mind...

Started by Yuri Patrick, Tue 18/09/2012 16:55:35

Previous topic - Next topic

Yuri Patrick

My mind seems to have recently turned to mush. ;)

I'm working away on my game and I remember that I wanted a audio display on the statusbar that says what the volume is set to, muted, 1-100, etc. Now, I can't remember how to get the current value of the volume out of AGS. :(

Can someone point me in the right direction, please? :)

Thanks.

Crimson Wizard

Depends on AGS version.
In AGS 3.2 it is System.Volume for master setting and AudioChannel.Volume for each of existing audio channels.

Yuri Patrick

Grrumpf! Like I said, brain death. I have a label on the status bar, lblVolume. When I try to get it to display the current volume, I get an error stating that I cannot convert an integer to a string. That's not what I'm trying to do. I'm trying to display the integer, for now.

Here's my code:
Code: AGS
lblVolume.Text = System.Volume;


And AGS' response to that line of code:
GlobalScript.asc(76): Error (line 76): Type mismatch: cannot convert 'int' to 'String*'

Hrm! Would a switching function work? If volume is 0, then it is muted, anything else means that it is on? But then, how do I get the current value of System.Volume into my label?

I just want to display OFF or the current volume level.

Crimson Wizard

#3
You cannot cast integer value (System.Volume) to string (lblVolume.Text) like that.
Printing numbers into string is done by the use of Format function.
You should definitely check manual for that, but here's quick example:

Code: ags

lblVolume.Text = String.Format("%d", System.Volume);


EDIT:
With "off":
Code: ags

if (System.Volume > 0)
{
   lblVolume.Text = String.Format("%d", System.Volume);
}
else
{
   lblVolume.Text = "OFF";
}

Yuri Patrick

Thank you sooo much, Crimson. I feel kinda silly. The if section was the easy part for me. However, the idea of a string.format was what was blowing my mind.

I know that everything is in the manual, but finding it either by search or by reading is difficult for me. :(

Thanks for the help again, Crimson. :)

BTW: I had some flags to animate in the background and was able to do that on my own. ;)

SMF spam blocked by CleanTalk