Help: How do I access type feilds without an insta

Blitz3D Forums/Blitz3D Beginners Area/Help: How do I access type feilds without an insta

WarpZone(Posted 2005) [#1]


There are plenty of tutorials and examples on how to use the this keyword to create instances of a type, but no mention of how to use a type directly. Any thoughts? I've already tried GlobalType.ScreenWidth like BlitzMax would use, but that doesn't seem to work, either. :/

Thanks in advance.


Matty(Posted 2005) [#2]
type globaltype
field scrwidth
field scrheight
end type

myglobal.globaltype=new globaltype
myglobal\scrwidth=800
myglobal\scrheight=600


;at any point later, assuming only the 1 globaltype instance exists

putyourinstancenamehere.globaltype=first globaltype
if putyourinstancenamehere.globaltype=null then runtimeerror("there aren't any global type instances")
[



WarpZone(Posted 2005) [#3]
You've got to be kidding me.

You mean you HAVE to make an instance of the type just to use it in Blitz3D? That's so messy. It's probabaly slower, too. *sigh* Oh well. :( Thanks.

I mean, I only wanted to use it to store globals... is this really that much better than simply declaring the globals? :/


Dreamora(Posted 2005) [#4]
No it is not better.
In Blitz3D you better just use an intelligent naming for variables.

There i no OO like in BM and types have their restriction due to their forced internal behavior with type lists etc


WarpZone(Posted 2005) [#5]
Okay.

So is it still recommended to place your global variables into a type like this so they generate compile errors if you misspell a variable name? Or is that wrong too?


Curtastic(Posted 2005) [#6]

So is it still recommended to place your global variables into a type like this so they generate compile errors if you misspell a variable name?


I highly recommend it.

In blitzmax you don't need to do hackey stuff like this. I take it for granted now, I can hardly code in blitz3d anymore


WarpZone(Posted 2005) [#7]
Yes, I know. BlitzMax would be great except the game I want to make kind of isn't 2D.


WolRon(Posted 2005) [#8]
So is it still recommended to place your global variables into a type like this so they generate compile errors if you misspell a variable name?
You don't have to use Types.

You can write (or acquire) a small program so that if you encounter any bugs, you can use it to check for one time variable usages and then list them.

99% of the time, solo-named variables are typos.


Red Ocktober(Posted 2005) [#9]
can i add just a penny and a half to this discussion...

WarpZone... i think that you are missing out on a lot of the advantages of using TYPEs... and there can be some OO like in 'Max... but you have to implement it...

but using TYPEs just to avoid globals... well, you are only dealing with part of the programming picture...

a lot of those globals might disappear inside of the instance for the TYPE that you are instantiating anyway,
plus... in almost any of these OOP languages, you've gotta instantiate an instance of a class in order for there to be an object at all...

organizational wise, wouldn't it be better to have the variables associated with the TYPE anyway... to me, that's the smartest way of naming variables...

also, function to create instances of TYPEs (objects) would be fail safe as they would only allow you to create an instance of the TYPE... wouldn't they...

now, you are definitely gonna be mixing in addressing the fields directly when you are writing the functions to make your TYPEs do things... but once that's done, you can call methods associated with 'objects' without ever touching the internal properties any more...

just some thoughts about it...

--Mike


Techlord(Posted 2005) [#10]
Issues like this is what inspired me to develop a online course: Applied Object-Based Programming with Blitz3D


Gauge(Posted 2005) [#11]
I guess I don't see the point in this problem at all. Its quite simple really. Types are for more then one instance, if not use globals and constants. As far as making all globals into a type to avoid error, well I've never had a problem with it, as for the typo part, well don't mistype them. If you add an extra or wrong character in any language your gonna screw it up.


LineOf7s(Posted 2005) [#12]
http://www.quickiegames.com/tools/preprocessor/

Option Explicit

Option Explicit is enabled by including the preprocessor directive "#Option Explicit" at the top of your source code. It will give an error whenever a variable is implicitly defined.

Is freeware. Is good. Will help. Do download.


Sledge(Posted 2005) [#13]
My variable names are generally so descriptive that it is faster to copy 'n' paste than type them. Problem avoided.


octothorpe(Posted 2005) [#14]
Or perhaps you need a text editor which will autocomplete variable names for you! ;)


VP(Posted 2005) [#15]
Getting the compiler to point out errors has got to be a better solution than "just don't mistype".

Reminds me of the comment "why is [the project] taking so long to debug? What are the bugs doing there in the first place? You shouldn't have been so sloppy". Made by a clueless boss.