May 08, 2024, 11:58:04 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


type question

Started by J B Wood (Zumwalt), December 26, 2006, 08:03:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

J B Wood (Zumwalt)

Actually, I wanted this to be ENUM, didn't find help on it so could this work?
I want to call this by doing IlluminationStrength.Dark
Any suggestions?

type IlluminationStrength
CONST Dark = 0
CONST Torch = 1
CONST Normal = 2
CONST Bright = 3
endtype

ExMember001

December 26, 2006, 08:31:48 PM #1 Last Edit: December 26, 2006, 08:35:11 PM by KrYpT
yep it should..
don't forget to define the structure before doing anything
def IlluminationStrength as IS

then use is.dark

if const didnt work replace it with int

Ionic Wind Support Team

The TYPE in that context is meaningless.  the constants are just numbers that the compiler inserts when you refer to their name, so all you would be doing is creating an empty type, and a bunch of constants.  Not that the syntax is valid of course.  And a TYPE is just a definition, it doesn't physically exist until you dimension a variable of that type.  So the assignments wouldn't work like that.


Enumerations will be a part of the language by 1.6.  The only thing you gain is less typing because enumerations just define the constants for you, and create a typdef to an int for the enumeration name.

enum IlluminationStrength
  Dark
  Torch
  Normal
  Light
endenum

Is the equivelent of:

typedef IlluminationStrength INT
CONST Dark = 0
CONST Torch = 1
CONST Normal = 2
CONST Bright = 3

Paul.
Ionic Wind Support Team

J B Wood (Zumwalt)

December 26, 2006, 08:47:09 PM #3 Last Edit: December 26, 2006, 08:52:43 PM by Jonathan (zumwalt) Wood
Sorry confused me.
So I can't use IlluminationStrength.Dark?
or the equivelent sentance you had means that I can use IlluminationStrength.Dark?

maybe I should elaborate:



type IlluminationStrength
def Dark as int = 0
def Torch as int = 1
def Normal as int = 2
def Bright as int = 3
endtype

def iStrength as IlluminationStrength


I don't think I can do it that way,  but maybe:


type IlluminationStrength
def Dark as int
Dark=0
def Torch as int
Torch=1
def Normal as int
Normal = 2
def Bright as int
Bright = 3
endtype

def iStrength as IlluminationStrength


Does that make better sense?

Ionic Wind Support Team

No.  Enumerations just define constants for you and a type defined name so you can use that name in functions as a type.

In either case once the enum is defined you can:

def lt as IlluminationStrength
...
if lt = Dark
...   
endif

etc.

We've had enumerations in Aurora for some time now.  I did explain there usage before ;)

Paul.
Ionic Wind Support Team

J B Wood (Zumwalt)

True, trying to find a solution to what exists now and still have my . in there :)
Forget enumerations for a second though, I'll revisit those later, but did what I just posted make more sense?

Ionic Wind Support Team

Um...why?  What purpose would it solve.  You could set up a type variable ahead of time, seems a waste of effort though ;)

type strengh
   def Dark as int
   def Torch as int
   def Normal as int
   def Bright as int
endtype

def IlluminationStrength as strength
IlluminationStrength.dark = 0
IlluminationStrength.torch= 1
IlluminationStrength.normal = 2
IlluminationStrength.bright = 3

And if it is a global variable you could use it anywhere.  Since you are used to Aurora a TYPE is the same as a STRUCT defintion, it is not a variable so you can't 'assign' something to it.  It is a defintion telling the compiler how to use a variable of that type once it has been created.  The def IlluminationStrength as strength  statement creates a variable of the type 'strength' and then it can be used.

If you are stumbling over using structures (UDT's) then please do some practice code with them before trying anything more complex with Emergence.  You will save yourself a bit of headaches then.
Ionic Wind Support Team

J B Wood (Zumwalt)

No problem with structures, I have issues at the end of the day coming home from countless hours of .Net using structures that I can NEW inside the structure which gives all children default values when you use the structure, sometimes confuses me.

I would like to have default values placed inside structures (aka types) in EBasic and Aurora also, but not worried about it, didn't know if you had it built in.
I have a reason why I need it this way.
Thanks for the help.

Ionic Wind Support Team

Well in Aurora it is simple enough to do with a class, in the constructor.  EBasic isn't object oriented so you can't expect .NET or C++ like functionality.  structures and classes are cousins when you refer to member variables, excuse the cross langauge post here:

class IlluminationStrength
{
int Dark, Torch, Normal, Light;
    declare IlluminationStrength()
    {
         Dark = 0;Torch=1;Normal=2;Light =3;
    }
}

IlluminationStrength IL;
IF light.Strength() = IL.Normal
{
}

etc.

C# probably allows constructors for structures which gives them default values.  Don't know as I don't use .Net or C#..never will either.

Paul.
Ionic Wind Support Team

J B Wood (Zumwalt)

Its cool, working within the limitations of EBasic for this project. I know how to do it as classes, wasn't the point of this particular project.
I appreciate the help, going to wrap this up for the night or I will drive you batty.