Development > Newbie Coding

Scripting questions, don't know if that constitutes coding

<< < (2/2)

joe davis:
Awesome, I have been studying this earlier and since I was experiencing problems with the code for the onClick event I switched over to the onChange event.  The onChange event works fine, not sure why the onClick didn't.  Also with the path confusion, I was trying to call something that wasn't defined yet so I put the check box after the bar and that helped immensely. 

I don't know about the integer and float values.  They work, guess I could make them both float, huh.

I appreciate this information about the echo and querying cvars.  That is very useful information.  I didn't know about that, was that in the documentation somewhere?

Since there isn't anything coded in C for the effects or music I will stick with my quasi coded solution and lower the volume to 0.0.

As to the cvars, guess I am still confused on how they work.  I have resolved to using surrounding values until it makes more sense to me.  And in regards to saving the previous value, prior to clicking on the checkbox, since it isn't in the CVAR_ARCHIVE, I will use arbitrary values that work for me.

That being said ,I have my first functional solution.  Thank you for your assistance with this.

The onClick event didn't seem to work so used the onChange event and got it to work. 

--- Code: --- checkbox effects_box
{
current *cvar:snd_volume
pos "85 170"
size "20 18"
image "ui/checkbox_blue"
onChange { if ( *node:this@current > 0 ) { *cvar:snd_volume = 0.5 }
else { *cvar:snd_volume = 0.0 }
             }
       
}

--- End code ---

The music check box is different due to the music_snd_volume being coded differently appearantly.


--- Code: --- checkbox music_box
{
current *cvar:snd_music_volume
pos "85 195"
size "20 18"
image "ui/checkbox_blue"
onChange { if ( *node:this@current > 0 ) { *cvar:snd_music_volume = 100.0 }
     else { *cvar:snd_music_volume = 0.0 }
             }
}

--- End code ---

interestingly enough this doesn't put the volume at 100% which I thought it would at first.  The position of the sound seemed fine so left it there.

As to the path, it would appear that my problem with that was I needed to define the check box after the bar since I was trying to call a property of the bar from the checkbox.  Silly me, huh.  lol.

But in the end I decided to change the sound cvars values instead of the bars current value.  This was primarily due to the fact that I couldn't get it to work by calling the bars current value.  Regardless, this works.

So I learned:

* the importance of spaces
* defining something prior to trying to use it
* and simple if else blocks
* about some basic debugging methods mentioned above(ie querying cvars, and use of echo   

I was confused 

* on why the check boxes onClick event didn't seem to want to work
* the sound volume for the effects and music were handled differently
Thanks for your assistance.

geever:

--- Quote from: joe davis on February 18, 2010, 04:37:11 am ---I was confused 
* on why the check boxes onClick event didn't seem to want to work

--- End quote ---

Hmm, it was not implemented. Bayo must have been a bit lazy on these... ;)
It's working from r28632.


--- Quote from: joe davis on February 18, 2010, 04:37:11 am ---* the sound volume for the effects and music were handled differently

--- End quote ---

That must be a legacy, I don't know...

-geever

Duke:

--- Quote from: joe davis on February 15, 2010, 09:34:06 pm ---Duke, I am sorry man, that went right over my head. 

Why is there a big difference with playing sound at 0.0 and not playing it at all?  Do you think I should release those resources instead of using them at an imperceptible level? 

--- End quote ---
Think of a radio. Turn down the volume to 0 but do NOT switch it off. You don't hear a thing, but the radio will still consume electric power (for UFO power translates to performance).
Not to mention erroneous situations like playing a corrupted sound file at a volume other than 0 ...

General IT design rule: if you don't want a function to do anything for you, DO NOT CALL it !
Got the idea ?

joe davis:
Duke that makes sense, though I would like to get more details on what you mean by
--- Quote ---Not to mention erroneous situations like playing a corrupted sound file at a volume other than 0 ...
--- End quote ---
  Is there a possible complication of me playing the volume at 0.0?  And how does this vary from me using the current gui layout to turn the volume of the effects or sound all the way down? 

  Basically all I am doing is adding a checkbox to turn the volume all the way down and, for aesthetic purposes, making sure that it plays well with the bar that is already there.  Are you seeing a possibility for future complications with the way that I am implementing it?

Duke:
I remember a situation with a different game. Whenever a certain crash occurred, the sound volume went to max and the last few millisecs of the sound were repeated until reboot. Very bad for my ears :(
Such things should not happen if sound is simply not active.

I can't tell you what can/will go wrong, but I know that the design I suggested will safely avoid some of the problems. Don't get me wrong: your approach for this sound thingy will probably never ever cause any problems. My point is: if you implement 20, 50 or 100 similar things with this design, it's almost certain that at least one of them will cause severe problems.

Navigation

[0] Message Index

[*] Previous page

Go to full version