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 / Floats Within Functions

Author
Message
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 21st Nov 2009 18:56 Edited at: 21st Nov 2009 19:00
Hi. I have a float in use within a function. The Float is involved an important calculation to display a number on a graph. The problem is that it does not act as a float while in the function. For some reason it acts as an integer and i have no idea why. I have tried declaring it as a Float in the Functions perameters but i get the number

Quote: "-1.#QNAN"


for some reason. When running it without declaring it as a float in the function i get the following error message:

Quote: "Cannot find structure 'Game_1:Quickinteger' in local declaration at line 292"


The functions name is Game_1(). The variables name is Quickinteger and line 292 is the line where the variable is used, but what is the problem in English? I then click okay and it runs the program but the variable appears as an integer.

I would like to say that the variable has already been declared as a float previously in the game.

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 21st Nov 2009 18:59
Is the variable declared as a GLOBAL ? - If it's not then the version inside the function will be a local.

A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 21st Nov 2009 19:01 Edited at: 21st Nov 2009 19:01
The Variable is only used as a local anyway but it is declared as:

GLOBAL Quickinteger AS FLOAT

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 21st Nov 2009 20:06
What is the line of code that causes this? It sounds like it is looking for a type structure, could just be a syntactical issue.

A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 21st Nov 2009 20:53 Edited at: 21st Nov 2009 20:53
I think that it may be best to post the whole code. I have solved it but im not sure how. It just seemed to fix itself after i messed about with some declarations within the function parameters.



This is my Game 1 graph drawing function and will have a line drawn, print out option and bookmark option put in once i get the hard stuff working. And then i will be repeating it for my second game.

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 24th Nov 2009 16:56 Edited at: 25th Nov 2009 15:14
If you did this before:


Then it might cause that issue? You definitely confused the compiler with some bad syntax. Glad you got it working. I would suggest using # at the end of float variables so when you're looking at your code you can instantly tell what type of variable it is.

local myFlt# as float
local myInt as integer
local myStr$ as string

I'm not a real programmer but I play one with DBPro!
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 25th Nov 2009 09:16 Edited at: 25th Nov 2009 09:17
Quote: ". I would suggest using # in front of float variables"


You mean after float variables like so...
Float#

Having the # before instructs the compiler that it's a pre-processor command like #include or #constant

Your signature has been erased by a mod because we are sadistic losers with nothing better to do. (mwahahaha!)
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 25th Nov 2009 10:19
A pre-processor? I dont really know what that is. But the error seemed to be with the parameters of the function() command.

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 25th Nov 2009 15:13
Sorry yes I meant after floats. Sorry for any confusion. Corrected original post.

I'm not a real programmer but I play one with DBPro!
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 25th Nov 2009 21:09
Pre-processor, as in before everything else. #include will include other functions and stuff BUT it's before the program runs. and #constant defines a variable that will be the same throughout the hole program and is unchangable. it does this before the program runs also.

New Site! Check it out \/
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 25th Nov 2009 21:59
Would it mean before processing? I havent heard it before but i can guess what it means

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 26th Nov 2009 14:26
Quote: "#include will include other functions and stuff BUT it's before the program runs."

Quote: "Would it mean before processing?"


Actually, it's before it compiles. When the editor/compiler is parsing the code into the FullSourceDump.dba it will replace all occurrences of #include with the entire contacts of the code it's including at that location. Likewise, #constant replaces all occurrences of it's variable name, with the numeric value associated to it.

Only after then, does the compiler actually compile the source code.

Your signature has been erased by a mod because we are sadistic losers with nothing better to do. (mwahahaha!)
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Nov 2009 14:47
Quote: "Likewise, #constant replaces all occurrences of it's variable name, with the numeric value associated to it."


Is that done before or after the include files are copied into the source?
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 26th Nov 2009 14:59 Edited at: 26th Nov 2009 15:00
Now that I don't know. I'd think after, as the editor includes them, but pre-processor commands are done by the compiler.

Or do you just mean the #include files?

If you mean are constants done before/after #includes then it'd probably be as the compiler gets to it.

Your signature has been erased by a mod because we are sadistic losers with nothing better to do. (mwahahaha!)

Login to post a reply

Server time is: 2026-06-11 14:46:03
Your offset time is: 2026-06-11 14:46:03