Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / alright, what did I do?

Author
Message
Chief Engineer
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United States
Posted: 11th Mar 2003 06:51
o.k., here's the deal. i've made a function (finally taught myself how to do it) that tells me how to set up the 'weather' for my map. here's the code for it:

function weather(weatherState)

randomize timer()

weatherState = RND(3)

`for late dusk
if weatherState = 0 or weatherState = 1
backdrop on : color backdrop RGB(30,60,100)
fog on : fog color RGB(30,60,100)
set ambient light 25
endif

`for foggy day
if weatherState = 2 or weatherState = 3
backdrop on : color backdrop RGB(128,128,128)
fog on : fog color RGB(128,128,128)
set ambient light 85
endif

endfunction weatherState

Then, in my prog (before the main loop) i have this to set up to play certain sounds depending on what the function returned:

`check weather state for sound usage
if weatherState = 0 or weatherState = 1
load sound "owl.wav",5
set sound volume 5,30
load sound "crickets.mp3",2
set sound volume 2,16
loop sound 2
endif

if weatherState = 2 or weatherState = 3
load sound "nigtengale.wav",5
set sound volume 5,30
endif

the problem is that when the 'day' value of the function is returned, the crickets and owl still play and the nightengale doesn't!

the sounds are not loaded anywhere else but one bit of code that may be the culprit (i've switched it up so many times yet i still have the same problem) is here:

`for the underwater stuff
if Y#
Chief Engineer
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United States
Posted: 11th Mar 2003 06:53
here's the code for the underwater stuff, the code button doesn't seem to be working:

`


sorry about the long post. i've tried everything that my noobie brain could concoct and i'm still stuck. any help would be greatly appreciated. thanx!
PiratSS
22
Years of Service
User Offline
Joined: 18th Oct 2002
Location:
Posted: 11th Mar 2003 18:50
RANDOMIZE TIMER()
waterSound = RND(350)
if waterSound = 1 then play sound 6
if waterSound = 101 then play sound 6

1st thing: your Rnd is way too high to get 1 or 101


Toughest line of codecol$=asc(left(Pcol$)),1+str$(rev)+chr(80)+left(right(mid(name$),1),1)
Chief Engineer
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United States
Posted: 12th Mar 2003 00:57
pirat, i have no problem with that code, the underwater sound is fine, i set it high because i don't want the underwater sound to play all the time. what i'm having trouble with is that my cricket sound plays when it's 'daytime' in my game. i've been trying to figure out why it does that.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 12th Mar 2003 03:10
weather 0 or 1 = dusk
weather 2 or 3= day

if weatherState = 1 or weatherState = 3
resume sound 2
endif


sound 2 is cricket

so this line says if weather=1 (dusk) or weather=3 (day) then resume cricket sound. ie play cricket day or play cricket night.

maybe line should be:
if weatherState = 0 or weatherState = 1
resume sound 2
endif
Danmatsuma
21
Years of Service
User Offline
Joined: 2nd Mar 2003
Location: Australia
Posted: 12th Mar 2003 07:28
Sometimes it's better to use > < instead of =
also you might wanna check out select - endselect
you could simplify that code so much, then i'm sure you could work it out for yourself.
Rewrite the whole thing using what you learned, you'll kick yourself i swear!!

hint: load the sounds somewhere in an initialization subroutine and stop,pause or play them with your function
instead of loading them everytime, use the "if sound exist()=1" command to work out if it needs to be loaded again...

ZX Spectrum 48k Issue 3, Radio shack Tape drive, Rank arena 12" T.V. set.
Trev C
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: United Kingdom
Posted: 12th Mar 2003 14:49
Silly question but do you call the weatherstate function anywhere to get the random variable returned?

If you don't do a call to the function then you'll always have a 0 value for the variable weatherState in the main part of the program. Try adding this to the main loop if not already there.

weatherState = weather()

This will then return the value created for the internal weatherState value of the function, which I believe is not globally available, meaning it is only available from within the function, unless you set something to the return value you have declared.

Hope this helps and is correct, I haven't tried it yet.

Trev C
Trev C
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: United Kingdom
Posted: 12th Mar 2003 14:56
Try this bit of code to see what I mean :



The value of state in the main loop is always 0, but value returns the value passed back from the 'state' function.

should make things clearer

Trev C
Chief Engineer
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United States
Posted: 13th Mar 2003 06:07
thanx for the help, i'll give these ideas a try and let you know how it turns out!
Chief Engineer
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United States
Posted: 13th Mar 2003 06:10
Trev C, what i had in my prog, before the main loop was
weather(weatherstate)

which weather is the name of the function, and weatherState was the value returned. I checked the DB examples, and i thought that part was correct. was i mistaken? did i miss something?
Trev C
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: United Kingdom
Posted: 13th Mar 2003 16:34
I tried that, but if you just call the function with: -

weather(weatherstate)

It does not update the value of weatherstate from the main loop i.e. the NEW value is only held during the execution of the function and not returned to the main routine.

The way to get the return value passed back from the weather function is to set a value equal to it, like: -

weatherstate=weather(weatherstate)

I think you are mixing up parameters and return values. The Parameter part weather(weatherstate) is used to pass data to the function only. This is so that you can pass variables of your main program into a function that may affect the processing within it.

In this case you do not even need the parameter of weatherstate because you reset it every time at the start of the function. You would only need it if you set the value in your main program and need to pass it to the weather function.

The return_value is data you may wish to return to the main body of the program, this is correct as you wish to return the new value of weatherstate, however you still need to set a variable to the value so you know what was returned from the function.

Does this make sense?

Trev C
Chief Engineer
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United States
Posted: 14th Mar 2003 03:31
Trev C, i sincerely thank you for that. That explains so much, i didn't realize how backwards i had my code. i'm going to fix it now to try it out. thanx for the info!
Danmatsuma
21
Years of Service
User Offline
Joined: 2nd Mar 2003
Location: Australia
Posted: 14th Mar 2003 07:24
kicking yourself i bet...

ZX Spectrum 48k Issue 3, Radio shack Tape drive, Rank arena 12" T.V. set.
Chief Engineer
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United States
Posted: 15th Mar 2003 19:02
you know it,Danmtsuma

Login to post a reply

Server time is: 2024-11-13 00:06:07
Your offset time is: 2024-11-13 00:06:07