Modifying a type from a function

Blitz3D Forums/Blitz3D Programming/Modifying a type from a function

slenkar(Posted 2004) [#1]
O.K. some questions please

1.How do I create a function to modify values in a type without calling the type in the function?
e,g,
for b.blue_car=each blue_car
damage_car(blue_car,20)
next

function damage_car
b.hull=b.hull-20
end function


2.Can one function be used to modify 2 different types?
e.g.
for b.blue_car =each blue_car
damage_car(blue_car,20)
next

for b.blue_van=each blue_van
damage_car(blue_van,20)
next


or do I have to create a damage_van function??


Jeppe Nielsen(Posted 2004) [#2]
1.
for b.blue_car=each blue_car
damage_car(blue_car,20)
next

function damage_car(b.blue_car,damage)
b\hull=b\hull-damage
end function

2. No, not directly, you could use the object/handle commands, but it will not be elegant.
Instead why not create one type called vehicle, and then have a field called class, that defines whether its a car or, like in your question, a van, or whatever?

Hope this helps.


slenkar(Posted 2004) [#3]
o.k. thats good thanks
P.S. can your GUI be used for blitz3D


Jeppe Nielsen(Posted 2004) [#4]
Yes, only for Blitz3D, as it uses quads to display it.


mr.ninja(Posted 2004) [#5]
I was about to ask the same question, but I found this thread first.

I have another question, though:

What if I have

for b.blue_car=each blue_car...

and

for c.blue_car=each blue_car...


How can I access b\hull, c\hull etc. from the same function?


Thanks a lot
Paolo


Jeppe Nielsen(Posted 2004) [#6]
Oops, the above piece of code was wrong, here is the corrected:
for b.blue_car=each blue_car
damage_car(b,20)
next

function damage_car(b.blue_car,damage)
b\hull=b\hull-damage
end function


@mr.ninja
You can use the same function like this:
for b.blue_car=each blue_car
damage_car(b,20)
next
for c.blue_car=each blue_car
damage_car(c,20)
next



mr.ninja(Posted 2004) [#7]
Thanks a lot!

Paolo