copying info from type to another

Blitz3D Forums/Blitz3D Programming/copying info from type to another

slenkar(Posted 2004) [#1]
I have 2 types of people, some that are in a city and some that are out in the battlefield.
This helps the battle go smoothly because there are less type instances to worry about when calculating the closest enemy etc.

I need to copy the info from a city person into another type called warrior person when they leave the city and join the battle.


I tried this:
positionentity s\handle,0,0,0
create_warrior(s)

function create_warrior(s)
w.warrior=new warrior
w\handle=s\handle
end function


the error message ['illegal type conversion'] happens at
the call to the create_warrior(s) function

Why doesnt this work? and what is the best way to create a copy of a type?


jhocking(Posted 2004) [#2]
The function declaration should be:
Function create_warrior(s.warrior)

You need to tell it that s is an instance of the warrior type.


slenkar(Posted 2004) [#3]
thanks matey


slenkar(Posted 2004) [#4]
oops didnt work,

let me show you more:
c.citizen=new citizen
c\handle=copyentity(citizen)
if c\leave_city=yes
create_warrior(c.citizen)
endif



function create_warrior(c)
w.warrior=new warrior
w\handle=c\handle
end function



Gabriel(Posted 2004) [#5]
function create_warrior(c.citizen)



slenkar(Posted 2004) [#6]
thanks that worked


SoggyP(Posted 2004) [#7]
Hi Folks,

So Slenkar, can you then delete the item from the citizen-type list, leaving the details intact in the warrior-type list? Or is it still present in the citizen list and just skipped over through use of a flag?

Later,

Jes


slenkar(Posted 2004) [#8]
you can do a

delete c

and the citizen is no more...


jhocking(Posted 2004) [#9]
*smacks forehead*
You put the type declaration in the wrong place. It has to be when you declare the function, not simply when you call the function. Note that Sybixsus wrote the same thing I did.


SoggyP(Posted 2004) [#10]
Hi Folks,

@Slenkar: I know that. Apologies, I thought you were trying something else, ie, copying all the values from the citizen into the warrior in one go, but that's not the case is it?

Later,

Jes


slenkar(Posted 2004) [#11]
soggyP no,field by field

jhocking - oh yeah