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 / #include/adding source file doesnt seem to be doing anything...

Author
Message
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 31st Jul 2004 10:20
Ok so my game is doing pretty good. Ive got about 520 lines and i thought that its time to start include. So just to start out, i copy the code before the main loop that positions the player, sets his speed, etc. I make another file called basic_setup.dba. In that i make a function...blah blah blah. So then I load the function from the main source file, and nothing happens ! Then strangely, back in basic_setup.dba, i just put, "END" inside the function, and it works! when i load the game, it exits immediately!

Whats wrong??? Thanks
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 31st Jul 2004 11:20
Try putting the function at the end of the main source file to make sure the funtion works before moving it into another file.

If it works at the bottom of the main source then there is a problem with the includes.

If it doesn't work at the bottom of the main source then there is a problem with the funtion.

Also if you are using dbpro it's better to not use #include but to add the files in the files tab of the project manager.
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 31st Jul 2004 12:45 Edited at: 31st Jul 2004 13:00
I have db pro but i have to use include cuz i tried adding the file like you said but it didnt do anything... Ill try that thanks

[edit] tried it, nothin happened
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 31st Jul 2004 12:53
yeah, include via the ide


DBP_NETLIB_v1.4.3 - 65 FREE Functions * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 31st Jul 2004 13:04
well...err maybe im putting the wrong thing in the subroutine/function. heres a snippet of what i put

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 31st Jul 2004 13:21
you need Global variables in order for the fucntion to act on them

GLOBAL myStrVar as String

etc


DBP_NETLIB_v1.4.3 - 65 FREE Functions * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 31st Jul 2004 13:22
Oooo, duh, I remeber reading that somewhere, can I just put it at the top of the main source file?

Thanks
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 31st Jul 2004 23:05
yes but you must use GLOBAL keyword for the variables to be seen in functions.


DBP_NETLIB_v1.4.3 - 65 FREE Functions * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 1st Aug 2004 02:15
so it would look like this?
GLOBAL player_x as string
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 1st Aug 2004 02:54
yes but replace string with whatever variable type you need. I assume Player_X would be FLOAT


DBP_NETLIB_v1.4.3 - 65 FREE Functions * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 1st Aug 2004 03:11
Oh okay yeah that works. thx a lot
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 1st Aug 2004 04:55 Edited at: 1st Aug 2004 05:03
no problem. As good practice (imho) you should define variables explicitly, and use some notaion, either one or three letters...
(one letter for DBP is fine)

strUserName As String -or- sUserName As String
intPortNum As Integer -or- iPortNum As Integer
fltPositionX As Float -or- fPositionX As Float
dwoScore As DWord -or- dScore As DWord

You get the idea. The notation ahead of the var name gives you an idea of what type the variable is, without having to find the def in code if you forget.
Any one of these can be preceeded with GLOBAL to expose it to functions, as we stated earlier.

Also another method for safe variable declaration, or a type of Option Explicit is to put all your variables inside a User Defined Type. Currently an undeclared variable in DBP is allowed to compile but is treated as zero or "" empty string. This is all well and good until you spell a variable name wrong somewhere in code and the bug drives you mad trying to find it. Heres a simple way of protecting yourself from that potential nightmare.

Type Vars
strUserName As String
intPortNum As Integer
fltPositionX As Float
dwoScore As DWord
EndType

v as Vars

Now to get at your variables you need to type "v.strUserName" or "v.dwoScore" (as an example). So now, if you mispell the var name inside the type the compiler will throw an exception, thus eliminating variable misspellings.

good luck


DBP_NETLIB_v1.4.3 - 65 FREE Functions * Click Logo

Login to post a reply

Server time is: 2024-11-27 03:37:46
Your offset time is: 2024-11-27 03:37:46