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.

DarkBASIC Professional Discussion / putting games into functions help

Author
Message
MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 18th Nov 2010 12:00


This is my code currently, i am having problems putting it ino functions. I get so far but it doesnt work as well as it does when it doesnt use functions.

Any help?
Brk_oth
20
Years of Service
User Offline
Joined: 8th Aug 2005
Location: Australia
Posted: 18th Nov 2010 12:09
What problems do you have when you put it into functions?

Remember that only global variables can be accessed in all functions.
So if you have a function that uses the Ammo or spareammo variables you need to declare them as global.

No signature found...
MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 18th Nov 2010 12:12
Ammo and spareammo are now globals

Textures are missing and the bullet doesnt fire(the sphere doesnt appear).
Brk_oth
20
Years of Service
User Offline
Joined: 8th Aug 2005
Location: Australia
Posted: 18th Nov 2010 12:20
lets see what you have done with your go at putting it into functions then.

No signature found...
MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 18th Nov 2010 12:30


Bit of a mess really, but i have never done it before.
MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 18th Nov 2010 12:38 Edited at: 18th Nov 2010 12:38


Right done a little myelf again the only thing which is not appearing is the textures of the universe!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Nov 2010 12:39
I believe all variables used in player() that have not been declared at the very beginninig of your program as globals will be deleted every time you enter the function. Try using subroutines instead of functions.

TheComet

Brk_oth
20
Years of Service
User Offline
Joined: 8th Aug 2005
Location: Australia
Posted: 18th Nov 2010 12:40 Edited at: 18th Nov 2010 12:47
Well a reason for your problem might be because you went and put a whole lot of your code into a comment block at the end of your program.

Comet, He reassigns the variables in the player function each loop, so it doesnt matter that they are wiped.
But yes, subroutines are also a feasable way of breaking up your code.

No signature found...
Brk_oth
20
Years of Service
User Offline
Joined: 8th Aug 2005
Location: Australia
Posted: 18th Nov 2010 12:48
Oh the textures of the universe arent appearing.... umm have you got them in the same folder?

No signature found...
MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 18th Nov 2010 12:55
my only problem now is the texture of the universe not showing!!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Nov 2010 13:46
Hmm... Shouldn't you have a "sync" command inside the loop? Also, why do you put player() in a loop, when the main loop is already inside the function?

TheComet

MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 19th Nov 2010 10:12
Thanks all for your help!

Login to post a reply

Server time is: 2026-07-21 18:57:49
Your offset time is: 2026-07-21 18:57:49