copying info from type to another
Blitz3D Forums/Blitz3D Programming/copying info from type to another
| ||
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? |
| ||
The function declaration should be: Function create_warrior(s.warrior) You need to tell it that s is an instance of the warrior type. |
| ||
thanks matey |
| ||
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 |
| ||
function create_warrior(c.citizen) |
| ||
thanks that worked |
| ||
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 |
| ||
you can do a delete c and the citizen is no more... |
| ||
*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. |
| ||
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 |
| ||
soggyP no,field by field jhocking - oh yeah |