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 / I'm curious: why not assign values as they are initiated?

Author
Message
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 7th Feb 2012 23:33
This is just a curiousity. Has anyone found any issues assigning values using the initators:

Global Number = 4
Local Name$ = "Tom"
Local Bill

The reason why I ask is because generally, Lee does not do it, and I see alot of people assign a value in a new chunk of code.

Lee tends to assigns a value after the declaration like so: Global Number : Number = 4, but I am not sure why.

The compiler is a little fussy about floats when initiating though:

Global Float# = 4 "Initialisation data '4' is incompatible"
Solution: Global Float# = 4.0

Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 7th Feb 2012 23:54
I only do it like Lee because there was a time when the IDE gave me an error otherwise.

Since then i was lazy to try again, and to be honest, don't want AN OTHER random bug report from the IDE, which i would AGAIN hunt for half a day, just to realize that it was the global variable declaration all along.

I'm way too fed up with error messages about a ghost 1400. line when there are only 700 lines of code to deal with that, thank you.

(sorry if i sounded harsh, the ghost line phenomenon is a very recent stuff, and cost me some precious time... again...)

-Mental Hybrid: A unique heavy story based shoot'em ~40% (primary project)
-CoreFleet: An underground commander unit based RTS (canned) ~15%
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Feb 2012 00:57
It's handy to have numbers set up at the beginning. Like Intro = 0 to skip the intro to your game.

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Feb 2012 03:12
I've had problems in that past where certain initialisers were ignored, this may have been fixed though...

[b]
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 8th Feb 2012 05:54
Thanks all; that makes sense now.

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 8th Feb 2012 21:17
Not particularly in DBpro,, but in other languages I would initialize variables to some Null value. The reason being...

Some languages you couldn't be 100% sure what values may reside during declaration. So just to be certain that the garbage was cleared out, I would use a value like -1. Some variables may not be known until run-time,, and rather than give it a value that may give the impression that my code is doing what I expect. I've found it easier, in a variable watcher, to identify variables that may not be initializing properly or that I have forgotten about, if I can see some unexpected value like -1, or "NULL", or -127 for a signed byte. Whatever would make it stand out to me.

~ZENassem
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 12th Feb 2012 22:18
and I thought I had Globals all figured out...

Login to post a reply

Server time is: 2026-07-09 17:42:27
Your offset time is: 2026-07-09 17:42:27