PDA

View Full Version : udt and experiments :)



Lionheart008
15-07-2009, 19:08
hi dear thinbasic users,

I am very seldom use UDT's but in this case I tested it :) original I wanted to test my liongfx module with udt, but only to replace it for printl messages it doesn't satisfy me ;)

at the beginning of the script you will find some "1" and "2" trees... (why ?) I was suprised to see it, have made experiments with print and other things you can see between the lines...

perhaps somebody can check this script if this udt example works...


uses "console" '- , "liongfx"

printl "one little udt example.. :)"
printl

'----------------- part one :)

TYPE Apple
r as integer
s as integer
color as string
pants as string
END TYPE

TYPE Comix
batman as long
hulk as integer
spiderman as string
xmen as string
transmitter as Apple
startrek as Apple
END TYPE

TYPE Horror
jimmy as long
paula as string
thething(5) as comix
jake(10) as comix
END TYPE

dim monster(6) as Horror
dim lover(6) as Horror ' as Comix doesn't run ;)

dim k as long
%marvelhits = 1
For k as long = 1 to 5
monster(1).thething(k).transmitter = %marvelhits
printl monster(1)
NEXT

printl "jimi hendrix was the best guitar men forever :)"

'-- this second part is dangerous...!
'dim r as long
'%asterix = 2
'For r as long = 1 to 5
' lover(1).jake(r).startrek = %asterix
' printl lover(1)
'NEXT


'------- only an experiments ;)

function monsterli (byref tyrex as long) as long
dim v as long
v += 1
monster(10) = 400 + "Filippo"
monster(20) = 300 + "Sharky"
monster(30) = 300 + "Housewife"
monster(40) = 200 + "Tsunami"
monster(50) = 100 + "King Kong"
monster(60) = 500 + "Minotaurus"
tyrex(v) = 1200 + "Olga"
end function

printl

'----------------- part two :)

dim a,b,c as Apple
dim d,e,f as Apple

dim g,h,i as Comix

a.color = "red"
b.color = "green"
c.color = "blue"

d.pants = "jeans"
e.pants = "wranglers"
f.pants = "armani"

g.batman = 189
h.spiderman = "yes, next spiderman movie will come 2010"
i.xmen = "..what a surprise: woolverine has got new friends"

IF a.color = b.color THEN
printl "equal"
ELSE
printl "unequal"
end if
printl

sleep 1500
printl "first color: " + a.color
printl "another nice color: " + c.color
printl "third famous color: " + b.color
printl
printl "my first trousers: " + d.pants
printl "your second trousers: " + e.pants
printl
printl "her third trousers: " + f.pants
printl
printl "how much comic books I have?: " + g.batman
printl
printl "does peter parker will come back? " + h.spiderman
printl
printl "woolverine is unburstable and an alien, but.. " + i.xmen
printl
printl "press any key to exit"


waitkey

the problem was to use this one... will check, why it doesn't work... if you are using it you will get a gpf at the end of the script... sorry... have noticed this mistake after second test with my laptop...



dim r as long
%asterix = 2
For r as long = 1 to 5
lover(1).jake(r).startrek = %asterix
printl lover(1)
NEXT

the included dummy function is still a further try for part two of the script to use it ;) more to come.

best regards, nice evening, mr. experimento :)

Petr Schreiber
16-07-2009, 08:26
Frank,

you catched yourself into own trap with following :):


dim r as long
%asterix = 2
For r as long = 1 to 5
lover(1).jake(r).startrek = %asterix
printl lover(1)
NEXT


Lover is of type Horror. So it can have members: jimmy, paula, theThing(1 to 5) or jake(1 to 10).

Lover(1).jake(r) => correct, if dotted further:

jake() is of type comix, which can have members: batman, hulk, spiderman, xmen, transmitter, starttrek

Lover(1).jake(r).startrek => correct, if dotted further:

startrek is of type Apple, which can have members: r, s, color, pants

but you did not listed any of these members.

So you would have to type something like:


lover(1).jake(r).startrek.r = %asterix


Your assignment:


lover(1).jake(r).startrek = %asterix

would be possible for assigning variable of type Apple, not number.

Lionheart008
16-07-2009, 10:36
good morning petr,

thank you... I see my mistake... and have checked this early morning another part of going with


dim r as long
%asterix = 2
For r as long = 1 to 4
lover(1).jake(r).startrek.weapon(4) = %asterix
printl lover(1)
NEXT


and added for type apple weapon(4) ... tested it with r and s(1) too ... it works... :)


TYPE Apple
r as integer
s(1) as integer
color as string
pants as string
weapon(4) as long
END TYPE

your idea is very good with eg.


dim r as long
%asterix = 2
For r as long = 1 to 5
lover(1).jake(r).startrek.r = %asterix
printl lover(1)
NEXT

I believe UDT's aren't my best friends ;) no, no... just a joke...

thank you for help..., nice day, I hope with a lot of sun bathing... or icecream...

lionheart

Michael Clease
20-07-2009, 14:14
"woolverine"

OIC. The new X-men character - Half Man Half Sheep. baaa :yes: