Darwinbots Forum
Code center => Darwinbots Program Source Code => Topic started 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?
-
The . only works if the thing in front of it is a class or a type.
-
oh, and how do I make a class/type and what do they serv for purpose?
-
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.
-
Hehe, the filter problem ;)
-
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.
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
with newtest
for t = 1 to 1000
.subtest1 = t
next t
end with
Does that make a little sense now?
-
it did make sense acctualy, so the types are to groupthing toghater like that and to be used with . s?
-
Thread split and moved to keep bug reports on topic.
-
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.
-
sweet sweetety sweet sweet
ned flanders
-
is it so aswell with types that I have to write it like formname.thing when I load from another form or file thing?
-
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"
-
sweet:D
-
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?
-
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.
-
Private Type location
X As Integer
why As Integer
End Type
Public position As location
ive done this and it complains, why?
-
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.
-
That code works if you use
Dim position As location
if you code it in a form, but the code you posted will work fine if put in a module.
-
oh
-
Indeed....
....
....
Did you understand what I said?? :D
-
Modules and forms have quirks that way. Never understood why.