Darwinbots Forum

Code center => Darwinbots Program Source Code => Topic started by: Zelos on November 01, 2005, 12:12:01 PM

Title: Types and members
Post by: Zelos on November 01, 2005, 12:12:01 PM
I know it has nothing to do with this, once again, but when I see
rob(Shots(t).Parent).kills
I see tehre is "."s and when I try in vb to use "." it just complain, why?
Title: Types and members
Post by: Numsgil on November 01, 2005, 12:16:29 PM
The . only works if the thing in front of it is a class or a type.
Title: Types and members
Post by: Zelos on November 01, 2005, 01:04:44 PM
oh, and how do I make a class/type and what do they serv for purpose?
Title: Types and members
Post by: Numsgil on November 01, 2005, 01:16:26 PM
Types are logical units you can use to combine variables togehter with.

For instance, if you have a point, it would be good to define it thusly:

type point
x as single
why as single
end type

instead of:

x as single
why as single

by themselves.
Title: Types and members
Post by: Numsgil on November 01, 2005, 01:16:49 PM
Hehe, the filter problem ;)
Title: Types and members
Post by: PurpleYouko on November 01, 2005, 01:21:41 PM
Have a look at the top of the "robots" module. You will see a whole bunch of variables, constants and types defined.

The primary one is the "robot" type

Later, rob() is defined as robot.

here is an example.

Code: [Select]
Private type test
  subtest1 as integer
  subtest2 as string
  subtest3 as long
end type

public newtest(1000) as test

Using this we define "test" as a type, then we add subtest1, 2 and 3 as members.

We can't actually use "test" in the main program as it is "type" rather than a variable, so we have to make a variable that mirrors the "type"

"public newtest(1000) as test" defines a new user type, "newtest" as the same format as the original "test" type.
In addition we now have it as an array with 1000 elements.

In the main loop we can now address things like....

newtest(389).subtest2

as a variable because subtest2 is a "member" of the "type"

In addition we can write stuff like

Code: [Select]
with newtest
  for t = 1 to 1000
    .subtest1 = t
  next t
end with

Does that make a little sense now?
Title: Types and members
Post by: Zelos on November 01, 2005, 01:33:37 PM
it did make sense acctualy, so the types are to groupthing toghater like that and to be used with . s?
Title: Types and members
Post by: PurpleYouko on November 01, 2005, 02:00:39 PM
Thread split and moved to keep bug reports on topic.
Title: Types and members
Post by: PurpleYouko on November 01, 2005, 02:01:08 PM
Quote
it did make sense acctualy, so the types are to groupthing toghater like that and to be used with . s?
That is pretty much it.
Title: Types and members
Post by: Zelos on November 01, 2005, 02:41:14 PM
sweet sweetety sweet sweet
ned flanders
Title: Types and members
Post by: Zelos on November 01, 2005, 03:24:24 PM
is it so aswell with types that I have to write it like formname.thing when I load from another form or file thing?
Title: Types and members
Post by: PurpleYouko on November 01, 2005, 03:28:14 PM
That depends a lot if you set them up as public or private types.
Public is accessable from anywhere. Private is accessable only in the same module or form.

In DB, "bot()" is defined as public so it can be accessed from anywhere in the whole program without need to say "form1.bot(23).nrg". We just use "bot(23).nrg"
Title: Types and members
Post by: Zelos on November 01, 2005, 03:33:37 PM
sweet:D
Title: Types and members
Post by: Endy on November 01, 2005, 09:33:46 PM
Quote
Public is accessable from anywhere. Private is accessable only in the same module or form.

So would changing a var from private to public have any negative affects?
Title: Types and members
Post by: Numsgil on November 01, 2005, 10:36:05 PM
It ruins encapsulation.

ie:

(in software engineering) the process of enclosing programming elements inside a larger, more abstract entity, similar to information hiding and separation of concerns. It is often associated with Object Oriented Programming. One or more of these attributes are often associated with the term:

    * Physically grouping together related operations or things.
    * "Gate keeper" of state or data; a single access point.
    * Hiding implementation details so that the external world only sees an interface. Note that functions also provide this capability.

So the code can could care less, but programmers upkeeping your code are apt to become sloppy and not use your type the way you intended.
Title: Types and members
Post by: Zelos on November 02, 2005, 02:11:55 AM
Code: [Select]
Private Type location
X As Integer
why As Integer
End Type
Public position As location
ive done this and it complains, why?
Title: Types and members
Post by: Endy on November 02, 2005, 02:35:35 AM
Quote
So the code can could care less, but programmers upkeeping your code are apt to become sloppy and not use your type the way you intended.

Okay, I think I understand what you're saying. Mainly I was asking so I could see about adding sons, refsons, trefsons.
Title: Types and members
Post by: Ulciscor on November 02, 2005, 02:36:35 AM
That code works if you use

Code: [Select]
Dim position As location
if you code it in a form, but the code you posted will work fine if put in a module.
Title: Types and members
Post by: Zelos on November 02, 2005, 02:50:12 AM
oh
Title: Types and members
Post by: Ulciscor on November 02, 2005, 02:51:43 AM
Indeed....

....

....

Did you understand what I said?? :D
Title: Types and members
Post by: Numsgil on November 02, 2005, 09:34:26 AM
Modules and forms have quirks that way.  Never understood why.