Page 1 of 1

Changing Text Actor Text without Using MouseDown Event

PostPosted: Thu Jun 01, 2006 8:04 pm
by plinydogg
Hi everyone,

I've got a spaceship traveling to another planet and when it reaches its destination, I want to change all of the info displayed on screen so that it reflects the new planet's info.

I'm using the script editor to do this and I've encountered no problem changing the image but I can't seem to get the text actors to change their contents (neither the text property nor the textNumber property respond to my commands). I know the correct syntax for assigning numbers to text actors and for assigning text to text actors (using strcpy). Why isn't it working?

I read somewhere on the forum that this problem occurs with uninitialized string variables, but as far as I know, you can't initialize string variables in script. Right?

I also vaguely recall reading somewhere (but can't find it anymore) that you need a mousedown event in order to assign text to text actors. Is this true? If so, is there a workaround. Perhaps something using the char type?

Any help would be deeply appreciated!

P.S. If the workaround requires using the char type, it would be great if someone could explain the basics of using char, since I've never had to thusfar.

Re: Changing Text Actor Text without Using MouseDown Event

PostPosted: Thu Jun 01, 2006 9:48 pm
by makslane
Please, show the whole code that you use for change the text.

plinydogg wrote:I also vaguely recall reading somewhere (but can't find it anymore) that you need a mousedown event in order to assign text to text actors. Is this true?


No, is not

PostPosted: Thu Jun 01, 2006 10:15 pm
by plinydogg
Makslane,

Here's the code I use (it's pretty long, so I didn't include all of it, but if you really want me to, I will, just let me know):

void showPlanetInfo(int i)
{
Actor *p = planets[i];
strcpy(textName.text, p->planetName);
if(p->climate == 1)
{
ChangeAnimation("climatePicture", "climateDesert", NO_CHANGE);
}
textPopulationMax.textNumber = p->populationMax;
textPopulationCurrent.textNumber = p->population;
textProduction.textNumber = p->planetProduction;
textResearch.textNumber = p->planetResearch;
}

PostPosted: Thu Jun 01, 2006 10:44 pm
by makslane
Changing any of the internal Actor's variables (x, y, xscreen, yscreen, ...) has no effect on the Global Code.

To works, you must put some reference in the caller Script Editor (even a comment):

//textName
//textPopulationMax
//textPopulationCurrent
//textProduction
//textResearch

showPlanetInfo();

PostPosted: Thu Jun 08, 2006 5:08 pm
by plinydogg
Makslane,

I still can't get it to work for some reason. Where exactly do I need to put the comments?

sorry for being daft!

PostPosted: Thu Jun 08, 2006 5:35 pm
by makslane
You need put the references before call the funcion. In your case, when you call showPlanetInfo() function.

Can you post your current script code that call the showPlanetInfo() funcion?

PostPosted: Thu Jun 08, 2006 6:28 pm
by plinydogg
Here it is. As you can see, showPlanetInfo() is called from within another function in global code:

int checkLandingAbility(int j)
{
int dist = distance(playerShips[j]->x, playerShips[j]->y, playerShips[j] -> destx, playerShips[j] -> desty);
int planetToIdentify = playerShips[j]->pDestNum;
if(dist < playerSpeed)
{
playerShips[j]->shipInMotion = 0;
planets[planetToIdentify]->explored = 1;
showPlanetInfo(playerShips[j]->pDestNum);
return 1;
}
else
{
return 0;
}
}

PostPosted: Thu Jun 08, 2006 6:49 pm
by makslane
In this case you need put, in the caller code:

//textName
//textPopulationMax
//textPopulationCurrent
//textProduction
//textResearch

checkLandingAbility();

PostPosted: Thu Jun 08, 2006 7:09 pm
by plinydogg
Thanks for the speedy reply. Unfortunately, I still can't get it to work. I should have mentioned, perhaps, that the checkLandingAbility() function is called from a for loop within the nextTurn() function. Just to make sure that it didn't work, I copied and pasted the comment lines into every scope level (e.g., within the for loop, within the nextTurn() function, within everything else), but I still had no luck.

PostPosted: Fri Jun 09, 2006 1:32 am
by makslane
Just put the references in the Script Editor, not in global code