str_for_entfile using last model name?

Posted By: SH6811

str_for_entfile using last model name? - 01/23/08 19:35

Hello,

If I place the following code in the action attached to a model in order to "store" the name of the model for future use...why does the name that gets stored correspond to the LAST model that had this command in its action??

Code:

string entname(30);

action model1
{
...
str_for_entfile(entname, me); MODELS[my.offset] = handle(entname);
...
}
Posted By: raiden

Re: str_for_entfile using last model name? - 01/24/08 00:23

... and you have MODELS like this:
Code:

define max_models, 100;
var MODELS[max_models];


... and offset like this:
Code:

define offset, skill1;



Just wanted to make sure those things were setup correct.

-raiden
Posted By: SH6811

Re: str_for_entfile using last model name? - 01/24/08 00:26

Yes that's correct...
Posted By: raiden

Re: str_for_entfile using last model name? - 01/24/08 01:03

Some things to try:
1. str_cpy(entname," "); before initializing entname to the character name file.

2. wait(1); before str_for_entfile(entname,me);.

3. Create a text object displaying entname, and put a breakpoint in the action to see if the name does change(hold ctrl+space to continue breakpoint stops). This isn't a fix, but it may help spot the problem.

-raiden
Posted By: SH6811

Re: str_for_entfile using last model name? - 01/24/08 03:03

Thanks for your help...
Posted By: SH6811

Re: str_for_entfile using last model name? - 01/24/08 22:04

Hi,

I'm still having some trouble with this. I've determined that the original handles seem to be set incorrectly...but I do not understand why?

When an "ent_morph" is performed what happens to the SKILLs of the "ORIGINAL" entity (the entity that was morphed)???
Posted By: SH6811

Re: str_for_entfile using last model name? - 01/24/08 23:38

Hi,

Well I think I know what's happening however I have NO IDEA why?? It seems the assignment of the handle and subsequent calling of it works fine within the same function...but if the handle is assigned in one function and attempted to be called in another it doesn't work...for example:

function first()
{
index = 0;
SAMPLE_ENT = ptr_for_handle(Monsters[index]); //get entity pointer
str_cpy(entname, " "); str_for_entfile(entname, SAMPLE_ENT); //get file name
MODELS[SAMPLE_ENT.offset] = handle(entname); //store entity file name

...do stuff

DESC = ptr_for_handle(MODELS[SAMPLE_ENT.offset];
ent_morph(SAMPLE_ENT, DESC); //change back to "original" model/sprite
}

that above works FINE...however...

function first()
{
index = 0;
SAMPLE_ENT = ptr_for_handle(Monsters[index]); //get entity pointer
str_cpy(entname, " "); str_for_entfile(entname, SAMPLE_ENT); //get file name
MODELS[SAMPLE_ENT.offset] = handle(entname); //store entity file name
}

function second()
{
DESC = ptr_for_handle(MODELS[SAMPLE_ENT.offset];
ent_morph(SAMPLE_ENT, DESC); //change back to "original" model/sprite
}

This doesn't work at all, it simply uses the "last" entity that was accessed using the "str_for_entfile" command...WHY???
Posted By: raiden

Re: str_for_entfile using last model name? - 01/25/08 07:35

I believe your losing it because SAMPLE_ENT is not being intialized properly in the "second()" function. I had a much better explanation a couple of hours ago before I started scripting out your problem, but its 1:30am, and my brain is fried, so I can't remember what it was, .

Anyway, I hope you like this piece I did for you.
Code:
define maxModels, 100; // maximum models
define maxModelTypes, 10; // maximum model types
//--
define typeMONSTERS, 0;
//define up 9 more types here, must initialize to 1,2,3,4...
//--
define offset, skill1;
//--
var MODELS[maxModelTypes];
//--
// multiarray - supports 10 types of different models, up to 10 each
// i.e. typeMONSTERS with skill1 offset from 0-9
// typeTREES with skill1 offset from 0-9
// etc.
var MORPHMDLS[1000]; // 10x100 multiarray
//--
var fncMorphCheck;
//--
entity* tempPtr;
//--
string entname;
//--
function setEntName(mdlType,index)
{
if(mdlType == typeMONSTERS && index < maxModelTypes)
{
my = ptr_for_handle(MODELS[index]); // get me
}
//--
str_for_entfile(entname,my); // copy the entity into the string
//--
if(mdlType == typeMONSTERS && str_len(entname) > 0)
{
MORPHMDLS[typeMONSTERS*maxModels+index] = handle(entname); // save a handle to the string
}
// more types
//--
if(str_len(entname) == 0) { error("entname not initialized!"); }
if(index >= maxModelTypes || mdlType >= maxModelTypes){ error("Invalid type or index"); }
}
//--
function morphEntName(mdlType,index)
{
if(mdlType == typeMONSTERS && index < maxModelTypes)
{
my = ptr_for_handle(MODELS[index]); // get me
tempPtr = ptr_for_handle(MORPHMDLS[typeMONSTERS*maxModels+index]); // get ptr from name
if(tempPtr == NULL) { breakpoint; }
ent_morph(my,tempPtr); // morph me to ptr from name
}
// more types
//--
if(index >= maxModelTypes || mdlType >= maxModelTypes){ error("Invalid type or index"); }
}
//--
action entityMonster
{
if(my.offset < maxModelTypes) { MODELS[my.skill1] = handle(my); }
if(my.offset >= maxModelTypes) { error("Invalid offset!"); return; }
//--
setEntName(typeMONSTERS,my.skill1); // set the entity name
//--
//..testing
ent_morph(me,"ball.mdl");
//..
wait(-5);
morphEntName(typeMonsters,my.skill1); // get the entity name, and morph back
//--
}



Hope thats what your after, I tested it and it works great. Let em know if you have any questions.

-raiden
Posted By: SH6811

Re: str_for_entfile using last model name? - 02/09/08 02:49

Hi Raiden,

Sorry for the delay in the repsonse. I want to thank you for the code you wrote, that was very nice of you...

I used your code to work into mine and got some interesting results. Basically what I did (from memory here so it may not be exact...)

action MONSTER1
{
...
MODELS[my.skill1] = handle(my);
...
}

function first()
{
my = ptr_for_handle(MODELS[index]); // get me
str_for_entfile(entname,my); // copy the entity into the string
MORPHMDLS[index] = handle(entname); // save a handle to the string
}

function second
{
my = ptr_for_handle(MODELS[index]); // get me
tempPtr = ptr_for_handle(MORPHMDLS[my.offset]); // get ptr from name
ent_morph(my,tempPtr); // morph me to ptr from name
}

...that seemed to work fine, and thank you for that. My problem came when I did exactly the same thing for a second set of entities and set the pointers to another array...then I saw the original problem again. I have no idea as to why it does this...

I managed a work-around...so I'm just left with confusion as to what caused this odd behaviour. Thank you again for your help. Regards.
Posted By: testDummy

Re: str_for_entfile using last model name? - 02/10/08 20:12

Quoting SH6811.
Quote:

why does the name that gets stored correspond to the LAST model that had this command in its action??



?:
*index++, offset++, skill1++?
*raiden seems to use a simulated multi-dimensional array (diff)
*ent(ptr) == mutEnt(ptr)? handles same? (not new?)
*formally tell the engine it's a STRING*?
© 2024 lite-C Forums