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 / Subroutines Help

Author
Message
haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 6th Jun 2003 05:17
K well im makin an FPS, my first 1 so its not gunna be really complicated. I am making the load different guns when it needs to, and am uding subroutines for it. I have made the code that I wanted to use, I looked up how to to gosubs and all that, but it says "broke from nested subroutines." I put the code in box below, any help would be much appreciated.
Sup Kids
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 6th Jun 2003 23:57
first of all your program (like any DB program) would continuously loop within do-loop
therefore the if statement line will be invisible to it, unless you put it inside the do-loop or address it with an additional gosub.
the sintax checker is detecting this inconsistency telling you it's missing proper nesting..BUT..if you put the if ... inside the do loop the program will pass the sintax check and run but it will try to re-load again and again the gun (since gun#=1 is always valid) and you will get an object already exists error..

so you must change gun# variable to a neutral value ater having loaded the gun like:

do
if gun#=1 then gosub _gun1:gun#=0
if gun#=2 then gosub _gun2:gun#=0
if spacekey()=1 then gun#=2
loop

what is the gun#(10) array for?

i can t say more at this point because i can only guess..if you explain what you want to achieve exactly i may be able to help more..
haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 7th Jun 2003 04:17
hey, thanks for the reply, but i dont understand :-s . the gun#(10) was a mistake, i was tryin to figure out how to get it to work, but i guess I forgot to delete it. So i tried adding the gun#=0, but then the program didnt run at all, it would just keep loading and loading, and didnt do anything at all, just a blank screen. Id there anything else that I needed to put in that i just missed in ur text? i was a little confused by it. Thanks
~nick

Sup Kids
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 7th Jun 2003 20:24
Sorry it didn't help , i assumed those lines were just a part of more code
can you please explain better?
Is that code all you have so far or is it just a part of it?
and what are you after?
wanting to load and see your guns in turn ?
If that code is all you have, you are missing the sync commands, the set display commands and the object and camera position commands..
assuming so try this:

set display mode 800,600,16
autocam off
backdrop off
sync on
set camera range 10,10000
gun=1

do
if gun=1 then gosub _gun1:gun=0
if spacekey()=1 then gun=2:wait 50
if gun=2 then hide object 1:gosub _gun2:gun=0

position camera 0,0,-10000
point camera 0,0,0
sync
loop

rem load guns
_gun1:
load object "ak47.x", 1
load image "ak47.bmp",2
texture object 1,2
xrotate object 1,-90
yrotate object 1,180
scale object 1,7000,7000,7000
position object 1,0,0,0
return

_gun2:
load object "mp5.x", 2
load image "mp5.bmp",3
texture object 2,3
xrotate object 2,-90
yrotate object 2,180
scale object 2,7000,7000,7000
position object 2,0,0,0
return
Obear
23
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 8th Jun 2003 04:30 Edited at: 8th Jun 2003 04:44
OK im not sure what your code here is tryign to do, i cant se the nested problem but i can see other problemsdim

gun#(10)
gun#=1
rem run weapon gosubs
do this do loop will keep on loading the same modle and textureing it again and again and again, once you have laoded and textured the modle, why are you loading it again?
if gun#=1 then gosub _gun1
if gun#=2 then gosub _gun2
loop

if spacekey()=1 then gun#=2 this bit is not in a function or the main loop (which hasent any way of stoping to move on to the next line of code, so this line will never be run

rem load guns
_gun1:
load object "ak47.x", 1
load image "ak47.bmp",2
texture object 1,2
xrotate object 1,-90 cant have -90 got to be between 0 and 360
yrotate object 1,180
scale object 1, 7000,7000,7000
return

_gun2:
load object "mp5.x", 2
load image "mp5.bmp",3
texture object 2,3
xrotate object 2,-90
yrotate object 2,180
scale object 2, 7000,7000,7000
return


Prehaps you could give us some more information as to what these routeens are doing inside the game.

As it stands the program enters a never ending loop and as you defined gun as 1 just before the loop started it reads the first line, and says yup gun is = 1, so ill go to the _gun1 routeen.

In there it then loads a modle textures it rotates it a bit then returns to were it gosubed from, read the next line and says nope guns is not = 2 so i wont go to _gun2 routeen then goes back to the start of the loop again and says oh yes, gun is = 1 so then goes of to _gun1 routeen, loads the same modle textures that same modle, rotates it a bit more then goes back to were it gosubed from.

Rince and repeat for ever and ever.

So at the moment, im not sure what its trying to do, could you enlighen a little

haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 11th Jun 2003 00:40
ok sry. well first, i gotta make myslef feel smart, and correct u on 1 thing. u CAN rotate on object -90 degrees. its just saying rotate it back 90 instead of forward 290 or w/e the # is. But ok ill try again: I am startin an FPS. So far I have got the movent down, along with the the mouse look and stuff. Now, i can load the hun, position it, etc. on its own, ihave done it and it works fine (well not really, it still doesnnt totaly stick to screen) but now I am workin on the weapon switching system. I wanted to use subroutines cuz i wanted to learn how, not knowing they would cause such a problem. This is only the part of the code that isnt working, the rest works fine, and it has all the sync stuff and camera range. This code is to make it so when i press the space key, it will switch to the next weapon, and the weapon will be displayed in the right place on the screen. Thats pretty much it, thanks for all the replys.
~haXor

Sup Kids
Obear
23
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 11th Jun 2003 04:14 Edited at: 11th Jun 2003 04:28
Hmm you useing DB classic or DBpro because when i use minus numbers in Classic it gives me the error that it needs 0 - 360, maybe your useing pro, or my DB is screwed

Anyways i have below a code snippet you can cut and past as a stand anlone program, it basicly dose what you want it to do

if you run it as it is, you will see that by pressing the 1 and 2 keys, it changes from a plain object to a sphear, will be easy to change these objects for your weapon modles

Code..............

Rem initialize the gun variable to the first weapon
gun = 1

rem ******replace thses with the various gun modles
rem ******load them first then hide them so they dont
rem ******have to be loaded in game and slow it up
rem ******you dont hide object 1 as its the first weapon
rem ******and you proberly want that on show from the start
rem ******but all other weapons 3,4,5, etc should be hidden
rem ******as well
Make object cylinder 1,20
Make object plain 2,20,30

Hide Object 2

rem ******the main loop
Do
rem ******if key 1 is pressed gosub the change to gun 1 routeen
If Inkey$()="1" Then Gosub _Change_to_Gun_one:
rem ******if key 2 is pressed gosub the change to gun 2 routeen
If inkey$()="2" Then Gosub _Change_to_Gun_two:
Loop


_Change_to_Gun_one:

Rem *****checks to see if the gun already on screen
Rem *****is the same one, and if so come straight out
Rem *****of Routeen, no need to re show the same gun
IF gun = 1 then Return

Rem *****hides the gun currently on show
Hide Object (gun)

Rem *****Shows the gun that has been choosen and changes gun
Rem *****variable to the same as the new selected weapon
Show Object 1
gun = 1

Return

_Change_to_Gun_two:

Rem *****checks to see if the gun already on screen
Rem *****is the same one, and if so come straight out
Rem *****of Routeen, no need to re show the same gun
IF gun = 2 then Return

Rem *****hides the gun currently on show
Hide Object (gun)

Rem *****Shows the gun that has been choosen and changes gun
Rem *****variable to the same as the new selected weapon
Show Object 2
gun = 2

Return

END CODE..............

Put this into a blank new project and run it, see how it workds and them change the objects to your weaponds modles, then add to your game.

You can add more weaponds just add more Gosub routeens of the same just changeing the modle numbers and variables. Dont forget to load them and hide them all at the start first.

Also you will need to move and rotate each modle at the start after you load them to the right possition

haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 12th Jun 2003 03:49
ok well first, i have pro and u can rotate objects backwards i guess, but thats not the problem. OK i put in the code u supplied, but it didnt run, i guess a classic to pro problme or somthing. but im gettin closer now. instead of saying "broken from nested subroutine" it now just goes to the blank screen as if loading, but stays there and wont go away untill i exit the program. I will supplie all my code this time, except for the mouse look stuff which isnt the problem. It is in the box thingy below. I know the problem is somewhere between the "rem load weapon gosubs" and the return of the second weapon subroutine. Thanks
~haXor

Sup Kids
Obear
23
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 12th Jun 2003 22:59 Edited at: 12th Jun 2003 23:10
OK a few probs with what code you have provided, this is asuming there is nothing major you have excluded with the code.

ok here we go..

Code....Rem ***** Main Source File *****
Sync On
Sync Rate 30
Hide mouse
Backdrop on
Set camera range 1,5000

Rem make matrix
Make matrix 1,10000,10000,20,20

Rem texture matrix
Load image "grass1.bmp",1
Prepare matrix texture 1,1,1,1
Fill matrix 1,0,1

rem load guns
`AK47
load object "ak47.x", 1
load image "ak47.bmp",2
texture object 1,2
xrotate object 1,-90
yrotate object 1,180
scale object 1, 7000,7000,7000

`MP5
load object "mp5.x", 2
load image "mp5.bmp",3
texture object 2,3
xrotate object 2,-90
yrotate object 2,179
scale object 2, 7000,7000,7000

ok So far this seesm all good, you have set up the matric loaded the modles, rotated them etc

gun#=1

rem run weapon gosubs (problem starts here)
ok here is a probelm, you have just declaired the gun variable as 1 just before this do loop. the program enters the loop, sees the first line and says, "YUP, gun is equal to 1" so it gos to the _gun1: routeen.
The first line in the _gun1: routeen checks to see if the variable gun is 1, which it ISso it imeadiatly comes out of that routeen and goes back to the main loop.
Then next line checks to see if gun variable is 2, which it isnt so it never goes off to that routeen. It then loops back again and checks once more if gun is equal to 1, which it IS and it then goes AGAIN to the _gun 1 routeen.etc etc etc.

You have created a never ending loop, at no point in the main loop have you included any input from the user to change the value of gun, it always stays at the value of 1.

What you need is a couple of lines of code in the main Do loop that CHECKS to see if a key is being pressed.
Ok, take out these lines of code..

if gun#=1 then gosub _gun1
if gun#=2 then gosub _gun2

Then replace them with some key detect commands, IE for key 1 or key 2, then if any of those keys are being presed to gosub to the routeens you have created. that way if key 1 is presed it goes to the _gun 1 routeen, if key 2 is presed it goes to the _gun 2 routeen.


do gun is always going to be 1, there is no way in this loop to change anything
if gun#=1 then gosub _gun1
if gun#=2 then gosub _gun2
loop

rem load guns
_gun1:
IF gun# = 1 then Return
hide object gun#
show object 1
gun# = 1
return

_gun2: this routeen never gets run as gun is never equal to 2
IF gun# = 2 then Return
hide object gun#
show object 2
gun# = 2
return `````` problem ends here

Rem Refresh Screen
Sync
Loop is this loop command here for a reason? there is no Do for it above, the whole program contains only 1 DO in the main Do Loop, but it has 2 LOOP commands, one at the end of the main Do loop above and this one here. unless you hvae excluded code that this loop uses it needs to be deleted

Hope this is of some help

haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 13th Jun 2003 06:03
ok ty, im almost there now. lol this is getting very annoying. OK this is what is goin on now. I have taken out the gun# variable because there is no need for it now that i go directly from the input from the keys, which i added. It now just hides all other objects that the gun can be instead of hiding gun#. Now, instead of just loading and staying blank, it loads for half a second, then closes for no reason. I say i think im close because i had typed somthig wronge before i compiled and it loaded the gun and the matrix, but then an error occured and then i fixed it and it just exits right away. and yah sry about that last loop, it was an accident, i took out the mouse look part of my code to make it shorter. Ill post the new code, i bet i just did somthing wronge from what u said or somthin. THanks for the reply
~haXor

Sup Kids
haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 13th Jun 2003 06:05
oops code screwed up, its below

Sup Kids
Obear
23
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 15th Jun 2003 02:13 Edited at: 15th Jun 2003 02:23
OK first off, it is a good idea to keep that GUN variable in the game, reson being, if you look at the two routtens and how they work.

rem load guns
_gun1:
IF gun# = 1 then Return
hide object 2
show object 1
gun# = 1
return

_gun2:
IF gun# = 2 then Return
hide object 1
show object 2
gun# = 2
return

At the end of each of these routeens you are saying hide object 1 show object 2, which is fine cos as the moment you have only 2 weapons. But if you had 3 or more weapons, how are you going to detect in these routeens which weapon is curently active so you know to tell the computer which weapon to hide?

The answer is simple and it is why I included your gun variable in my first code posting.

instead of saying in each of the routeens HIDE OBJECT 2 or HIDE OBJECT 1, write HIDE OBJECT gun

In each routeen, you change the variable of gun to the object number of the weapon that is being selected, there for no matter how many weapons you have in your game, if you say HIDE OBJECT gun, you will be telling the compture to hide the object number of gun, which will be the very last weapon you choosen, even if its object 54.

That wasent so much a bug in this current state of code, but a problem that would arrise the moment you added just 1 extra weapon to the selection list.

ok now for your problem, im not sure what you are saying is happerning, are you saying you run the game and then half way though loading, it just stops?or dose it drop out of the game all together.

Below is basicly YOUR code you provided, i have REM'ed out all the loading of Modles and bitmaps because i dont have them on my PC and that would obviously cause an error.

And it their place i have created in just the same kind of way, simple 3D objects (a cube and a plain)

Now when i run this code (which is YOUR code but without the modles, it works just fine on my PC.

Can you cut and past this verion onto your PC in a blank new project and see if when run, you get to switch between a cube and a plain in the middle of the screen by pressing 1 or 2.

If it dose then obviously the code is working fine as far as the main loops key detection and routtens is concerned, so i would look at your modles loading, matrix textureing and bitmaps. Are the names EXACTLY right? is the syntax for these commands being used correctly. I dont have DB pro just classic, so i cant be sure.

you will also noticed i changed your ROTATE -90 command to ROTATE 90 as i said before, my verswion od DB classic dosent like minus rotaion numbers.

let me know how you get on and elaborate on that problem you are haveing.



Rem ***** Main Source File *****
Sync On
Sync Rate 30
Hide mouse
Backdrop on
Set camera range 1,5000

Rem make matrix
Make matrix 1,10000,10000,20,20

Rem texture matrix
rem Load image "grass1.bmp",1
rem Prepare matrix texture 1,1,1,1
rem Fill matrix 1,0,1

rem load guns
`AK47
rem load object "ak47.x", 1
rem load image "ak47.bmp",2
Make Object plain 1,10,10
rem texture object 1,2
xrotate object 1,90
yrotate object 1,180
scale object 1, 20,20,20

`MP5
rem load object "mp5.x",2
rem load image "mp5.bmp",3
make object cube 2,10
rem texture object 2,3
xrotate object 2,90
yrotate object 2,179
scale object 2, 20,20,20


rem load guns
_gun1:
IF gun# = 1 then Return
hide object 2
show object 1
gun# = 1
return

_gun2:
IF gun# = 2 then Return
hide object 1
show object 2
gun# = 2
return

Rem Main loop
Do

If Inkey$()="1" then gosub _gun1
If Inkey$()="2" then gosub _gun2


Rem Refresh Screen
Sync
loop

haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 17th Jun 2003 03:29
ok, well the code u put up doesnt run on my computer. Could it be a clasic-to-pro error? I dout it, but cant hurt to ask.

OK so what happens is that the program starts to load, the screen goes black, and then while loading dies and exits, going back to the compiler. so basicly it starts and then stops before it even shows somthing on the screen. thanks, i dunno, baybe its my comp or somthin.
~haXor

Sup Kids
Obear
23
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 17th Jun 2003 20:01
OKdoky, maybe my code dose not work because

a: there is somthing wrong with your PC setup or DBPro version

or

b: (and more likely) the task of putting objects like cubes and plains in Pro is diffrent to classic.

Anyways if your PC is locking up or crashing before the program gets a chance to utilize the key press commands. I would say its haveing a few probs with your inital setup. with either the graphics or 3D modles.

Ok here what to do, take your code, take out ALL the modles and ALL the graphics (bitmaps)

Just make a empty matrix and then instead of these modles place in there place simple objects like cubes/sphears?plains etc.

As i have Classic i dont know if it is diffrent in Pro, so you would have to find that out.

in classsic its Make object cube 1,20 or somthing like that, maybe pro is diffrent.

If it works, then its your grapics and modles and the syntax your useing to put them into the game may be wrong.

If it dosent maybe part of the cod eis wrong, make sure that for PRO key detection commands ARE

If INkey$()="1" THEN blah blah blah

and not somthing else.

sorry i cant help much more, but apart from your modles your code works fine in my verison of Classic.

As i havent go Pro i couldnt test it out for you on the same development enviroment.

Liek i said make sure its not your graphics and modles causien the prob, then try and check the code, specially the key detect commands, cos the rest is pretty much the same kinda syntax across the board in Basic programming.

Good luck, let me know if you have success.

haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 19th Jun 2003 17:23
well, i changed the INkey$ command to keystate, because thats easier and can have multiple keys at once. However, it still just loads for half a second then just exits back to the compiler. How would i go about checking my system stats, because it seems the problem is internal

Sup Kids
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 19th Jun 2003 21:28
this code works , just want to say that when your code isn`t working and people are spending time trying to help you out PLEASE don`t keep altering the code (like when you changed inkey$) because it could be that you just added another error to the code and made the problem worse, leave the code alone until you get it working and just make alterations that are to do with the problem, in this case I doubt you created problems, but it can happen and makes it harder to find a fault, thanks.
now as to what the problems where, you had the subroutines inside the code so that they got executed before you called them, so they hit a return instruction before they had been called, so the computer "returned" from the program, and didn`t give an error message, subroutines should be arranged in blocks after the main program, since the only way they should be entered is from a gosub, never in any other way.
like I say, this code example works, you get the objects to swap over when you press key one or two, I don`t know why the sync rate is set so low though , and you will need to reposition your camera (and the models) since you are at the edge of the matrix, but you have what you wanted

Rem ***** Main Source File *****
Sync On
Sync Rate 30
Hide mouse
Backdrop on
Set camera range 1,5000

Rem make matrix
Make matrix 1,10000,10000,20,20
set matrix wireframe off 1

Rem texture matrix
rem Load image "grass1.bmp",1
rem Prepare matrix texture 1,1,1,1
rem Fill matrix 1,0,1

rem load guns
`AK47
rem load object "ak47.x", 1
rem load image "ak47.bmp",2
Make Object sphere 1,10
rem texture object 1,2
xrotate object 1,90
yrotate object 1,180
scale object 1, 20,20,20

`MP5
rem load object "mp5.x",2
rem load image "mp5.bmp",3
make object cube 2,10
rem texture object 2,3
xrotate object 2,90
yrotate object 2,179
scale object 2, 20,20,20

Rem Main loop
Do

If Inkey$()="1" then gosub _gun1
If Inkey$()="2" then gosub _gun2


Rem Refresh Screen
Sync
loop

rem load guns
_gun1:
IF gun# = 1 then Return
hide object 2
show object 1
gun# = 1
return

_gun2:
IF gun# = 2 then Return
hide object 1
show object 2
gun# = 2
return

Cheers.

Mentor.

haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 19th Jun 2003 22:54
omg im such an idiot!!!!! ooo i feel soooo dumb now. i dont know why i didnt see that before. well thanks to all that helped, especialy mentor lol well now it works, halehluyah (spelling extream?)
~haXor

Sup Kids

Login to post a reply

Server time is: 2026-07-05 18:16:38
Your offset time is: 2026-07-05 18:16:38