Indigo Rose Software
  #1  
Old 11-14-2003
eric_darling's Avatar
eric_darling eric_darling is offline
Indigo Rose Customer
 
Join Date: Jun 2002
Location: Southeast USA
Posts: 1,804
Math Error

I'm having a problem with some simple math in AMS 5. I've enclosed my code that shows the problem below - with the responsible lines highlighted in red.

This is code for a Volume Up button. The problem is that this whole shebang works great until I get the volume of the video under 5. If I get down to 4 (using the volume down button), I cannot get the button to increment the volume up anymore. Once I get to zero, that's where I am forced to stay.

It seems buggish to me, since there's no apparently reasonable explanation for this behavior. What is of particular interest is that the reverse of this situation is not true once I get the volume up to 96.

I guess I could just drop the nice volume tethers at the top and bottom because of this issue, but I'd like an explanation regardless.

Anyone have a suggestion for something I'm doing wrong?

The first part of the code that checks the status of the video is implemented to deactivate button sounds while the video is playing.

Code:
IsPlaying = Video.GetState("Video1");
if (IsPlaying == 0 or IsPlaying == 1) then
Audio.Load(CHANNEL_EFFECTS, "AutoPlay\\Audio\\Click1.ogg", true, false);
end

v = Video.GetVolume("Video1");

if (v < 95) and (v > 4) then
Video.SetVolume("Video1", v + 5);
end

if (v >= 95) and (v < 100) then
Video.SetVolume("Video1", v + 1);
end

if (v <= 4) then
Video.SetVolume("Video1", v + 1);
end

Paragraph.SetText("volumetext", v);
Incidentally, the Paragraph.SetText command is for a paragraph object where I report the current volume based on the 'v' variable.
__________________
Eric Darling
eThree Media
http://www.ethreemedia.com
Reply With Quote
  #2  
Old 11-15-2003
Lorne's Avatar
Lorne Lorne is offline
Indigo Rose Staff Member
 
Join Date: Feb 2001
Location: Indigo Rose Software
Posts: 2,588
What's in your volume down button?
Reply With Quote
  #3  
Old 11-15-2003
eric_darling's Avatar
eric_darling eric_darling is offline
Indigo Rose Customer
 
Join Date: Jun 2002
Location: Southeast USA
Posts: 1,804
This is the code from Volume Down:
Code:
IsPlaying = Video.GetState("Video1");
if (IsPlaying == 0 or IsPlaying == 1) then
Audio.Load(CHANNEL_EFFECTS, "AutoPlay\\Audio\\Click1.ogg", true, false);
end

v = Video.GetVolume("Video1");

if (v > 5) and (v < 96) then
Video.SetVolume("Video1", v - 5);
end

if (v <= 5 and v > 0) then
Video.SetVolume("Video1", v - 1);
end

if (v >= 96) then
Video.SetVolume("Video1", v - 1);
end

Paragraph.SetText("volumetext", v);
Thanks for taking a look, Lorne.
__________________
Eric Darling
eThree Media
http://www.ethreemedia.com
Reply With Quote
  #4  
Old 11-15-2003
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
Hi. I think there's a more easy/streamlined method, but I don't understand why the increment value changes need to change on either end of the scale? What exactly are you trying to create Eric?

Corey Milner
Creative Director, Indigo Rose Software
Reply With Quote
  #5  
Old 11-15-2003
eric_darling's Avatar
eric_darling eric_darling is offline
Indigo Rose Customer
 
Join Date: Jun 2002
Location: Southeast USA
Posts: 1,804
Well, like I said, it's not mandatory for the project. I was just testing some scripting out in the new engine. I must say, it's more powerful and streamlined by nature. I think I'm really going to come around with it soon.

I originally thought it would be nice to have smaller increments in volume adjustment at the top and bottom of the range (top and bottom 5 numbers).

But I was asking out of interest for why it isn't working as expected. Volume Up works as it should. Why not volume down?

And, of course, I'd love to have a more streamlined method. Other suggestions for better implementation are always welcome. I've not thought about it from more than just the "how do I do it this way" perspective.
__________________
Eric Darling
eThree Media
http://www.ethreemedia.com
Reply With Quote
  #6  
Old 11-15-2003
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
I know, but I'm lousy at fixing code so it's just more time efficient for me to build you a working example. Attached is a working example which may or may not be simpler but is fairly lean, maybe Lorne can shed some light on the former. Off hand though I do notice you didn't put in any absolute limits, i.e.

if (volume > 100) then
volume = 100;
end

and

if (volume < 0) then
volume = 0;
end

But I don't know if this is the only issue or not... BTW if you are using this on different pages with different buttons, don't forget it can be defined as a global function. For example if you had several items in your project which act as 0-100 value counters you can define it as a function and then you can just fire that function whenever neccesary... Simplifies code and keeps things efficient.

Corey Milner
Creative Director, Indigo Rose Software
Attached Files
File Type: apz volume.apz (8.7 KB, 20 views)
Reply With Quote
  #7  
Old 11-15-2003
eric_darling's Avatar
eric_darling eric_darling is offline
Indigo Rose Customer
 
Join Date: Jun 2002
Location: Southeast USA
Posts: 1,804
Oh yeah... Functions. I forgot all about that. Thanks for the reminder! My head is still so, er... 4.0.

I didn't realize absolute limits were necessary since the volume couldn't be set outside the 0-100 range. Thanks for that as well. Will test and report back.
__________________
Eric Darling
eThree Media
http://www.ethreemedia.com
Reply With Quote
  #8  
Old 11-15-2003
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
Well in a sense you are right, you can't exceed the system limits for sure but it's good practice to manage your values but also it's mostly for the display value than anything. Although if you don't add limits, and your user clicks past zero a few times they would have to click back the same amount of times to get back to zero since the variable got clicked down to -4 or whatever. In the example I didn't add any actual volume control, but that would be easy enough with a single action added to the end of each button's actions. I was more hung up on making it just display the values here so you could see it works...

Corey Milner
Creative Director, Indigo Rose Software
Reply With Quote
  #9  
Old 11-16-2003
eric_darling's Avatar
eric_darling eric_darling is offline
Indigo Rose Customer
 
Join Date: Jun 2002
Location: Southeast USA
Posts: 1,804
Actually adding the limit commands did not affect the functionality (or dysfunctionality) of the scripts. In fact, it didn't affect their performance in any way.

So, I got to thinking about why this was happnin...

Turns out, AMS was referencing the first gathered variable 'v' for the current volume, where really, that value was just outdated by an adjustment to the volume on the video in the interim.

So, I simply added a second variable, 'v2' which does exactly the same thing, but it appears in the scripts after the volume adjustments occur (which I've now just simplified to blocks of 5 for both up and down). So, the setting of the paragraph text actually submits the 'v2' variable instead. Works like a charm.

This whole discussion has really got me thinking about how I code, though. The reminder about functions was crucial to me getting better at this kind of stuff - thanks, Corey!

Snippet of working code FYI:

Code:
IsPlaying = Video.GetState("Video1");
if (IsPlaying == 0 or IsPlaying == 1) then
Audio.Load(CHANNEL_EFFECTS, "AutoPlay\\Audio\\Click1.ogg", true, false);
end

v = Video.GetVolume("Video1");

if (v <= 95) then
Video.SetVolume("Video1", v + 5);
end

v2 = Video.GetVolume("Video1");
Paragraph.SetText("volumetext", v2);
__________________
Eric Darling
eThree Media
http://www.ethreemedia.com
Reply With Quote
  #10  
Old 11-16-2003
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
I try not to use 2 variables when 1 would do but I'm, "funny that way", it's no big deal either way on small to mid-size projects as long as you are able to read your own code quickly that's all that matters.

Corey Milner
Creative Director, Indigo Rose Software
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -6. The time now is 05:26 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software