textobj help

msmalik681

OpenBOR Developer
Staff member
I am trying to get the name, x and y property of a text object but i can only get z and y both return 30 with the below update script anything else crashes with no reason in the log.


Code:
void main()
{
settextobj(0, 35, 30, 3, 9999999999, "Test");
drawstring(10, 100, 3, gettextobjproperty(0, "text"));
}
 
you found a bug.
fixed!
download new openbor version at:
https://sourceforge.net/projects/openbor/files/?source=navbar
 
Thanks WD your the best this was driving me crazy !

Can I just ask is there anyway to clear all text in 1 line like cleartextobj(all); as I use a for loop to clear all text objects followed by the new command gotomainmenu(3); outside the loop but all text stays on screen as it fades out. I even added as if statement to check if i has reached the loop limit but text still stays on screen. but text is gone when I start a new game.
 
update.c

Code:
void main()
{


if(getindexedvar("1")!=NULL())
{
 if (!getentityproperty(getindexedvar("1"), "exists"))
 {
 
 int i;
 for(i=0;i<20;i++)
	{
	cleartextobj(i);
	}
	setmusicvolume(100,100);
	setindexedvar("1",NULL());
	setindexedvar("2",NULL());
	if(i>=20)
	{
	gotomainmenu(3);
	}
   }
 }
}

@White Dragon

I have tested your fix and here are the results:
Code:
void main()
{
settextobj(0, 35, 30, 3, 9999999999, "test"); //text object
drawstring(10, 70, 3, gettextobjproperty(0, "y")); //x value
drawstring(10, 100, 3, gettextobjproperty(0, "z")); //y value
drawstring(10, 130, 3, gettextobjproperty(0, "font")); //font
drawstring(10, 160, 3, gettextobjproperty(0, "text")); //text string
drawstring(10, 190, 3, gettextobjproperty(0, "a")); //y value
//engine crash//drawstring(10, 190, 3, gettextobjproperty(0, "time"));
//engine crash//drawstring(10, 160, 3, gettextobjproperty(0, "x")); 
}

I just cant get the layer value at the moment and the results seem wrong.  I found a comma missing after "time" in the source code of openborscript.c as shown below. could this be the reason its not working.

Code:
     static const char *proplist[] =
-    {
+    {
+        "a",
         "font",
         "text",
         "time"
         "x",
-        "a",
         "y",
         "z",
     };
 
Yes, that would do it. I'm on my phone qnd can't fix atm. If WD doesn't correct it, I'll do it soon as I get home tonight.
 
I really would appriciate the fix i really wanted to do it myself but i was worried i might break something lol and did u also look at my update.c and the text not clearing issue ?
 
there seems to be a restriction on how many characters a settextobj can hold is there a way around this or can the restriction be removed or increased in a future update ?
 
The restriction is 64 characters (remember everything is a character, including spaces), and there's a very good reason for it. I won't change nor allow other devs to change it for now.

You're really getting outside of what text objects were designed for at that point anyway. You can chain more of them together, but the obvious issue is getting location just right.  Might be time to start looking into screen objects. You'll still have to use text objects and more than one for 64+ characters, but it will make positioning and preparation a lot easier once you get the hang of it.

If you are interested, we can get into more detail later.

DC
 
sounds interesting more information would be appreciated !

I might try using drawstring unless that is also restricted to 64 characters  ?
 
msmalik681 said:
sounds interesting more information would be appreciated !

Soon as finals week is over I can do a bit more, I'm still under the gun until then.

I might try using drawstring unless that is also restricted to 64 characters  ?

First, just an FYI, stop thinking of drawstring or textobjects as different functionality. They're not. Text objects are really just a hard coded control method that runs drawstring for you. There's no reason or advantage to using drawstring manually except in very special circumstances.

Also note there is really no text limit at all aside from sprite availability (5000 as of this post). The limit is actually variable size. All OpenBOR variants are limited to 64 characters, so there's no way to pass any function more than 64 characters at a time. And right now, there's no feasible way to increase the limit without dramatically increasing the memory use of all scripts. That's why I won't allow it for the moment.

DC
 
sorry this was me being lazy and trying to get out of a bit of manual work I can work with text objects all your feedback is very much appreciated and helpful I hope to reveal soon what I am working on.
 
I have a for loop to cycle through text objects until it finds one with a set value but if it hits a uninitialized textbox the whole engine shuts down.  is there any way to check if a textbox index is initialized without crashing the engine I tried a not (!) statement with no luck.
 
I hate to interrupt this, but I find textobj really interesting. Since the Wiki is not up, I've forgotton how textobj was like.

I just learned about textobj which exists below and some types of textobj posted:

settextobj(index, x, y, font, z, text, time)

Is there a text object function with a z value for enemies similar to textobj we know? I want to set text like this below, but I dunno what type of function can work for them. I have no problem with players at all, but it's just enemies' name text with z setlayer is what I need.

settextobj(entity,x,y,font,z,text,time)
 
below is a example how you can manipulate text object by script:

changetextobjproperty(index,property,new value);


be careful if 2 entity's make a text object with the same index they will conflict.  This is just a on the fly idea I am not sure if there is a limit to the size a index number can be but to avoid conflicts you could use openbor current time as index value. Unless you save it somewhere it will be hard to manipulate the text object later.


remember if you do not set a time value the object will stay on screen until you clear it with cleartextobj(index);
 
I modified the enemy HP for drawing enemy's name string text. Look at drawstring here where the text object is which I commented.

Code:
void main() //Enemy HP
{
	if(getplayerproperty(0, "entity") == NULL() && getplayerproperty(1, "entity") == NULL()){
	    void vSelf      = getlocalvar("self");                  //Caller   
		int  iETime     = openborvariant("elapsed_time");       //Current time.
		int  iMax       = openborvariant("count_entities");            //Entity count.
		int  iEntity;                                           //Loop counter.
		void vEntity;                                           //Target entity.
		
		changeentityproperty(vSelf, "iconposition", 262, -121);

		for(iEntity=0; iEntity<iMax; iEntity++)
		{   
			vEntity = getentity(iEntity);                                       //Get target entity from current loop.       
			
			if (vEntity && vSelf)                                               //Both Self and Target?
			{
				changeentityproperty(vEntity, "frozen", 1);               //Toggle frozen.
				changeentityproperty(vEntity, "freezetime", 95000);    //Toggle frozen time.
			}
		}
	}
	else
	{
		void self = getlocalvar("self");
//		float z = getentityproperty(self, "z");
		int HP = getentityproperty(self, "health");
		int MaxHP = getentityproperty(self, "maxhealth");
		int health = 114*HP/MaxHP;
		int P1 = getplayerproperty(0, "entity");
		int P2 = getplayerproperty(1, "entity");
		void name = getentityproperty(self, "name");
//		void icon = loadsprite("data/profiles/"+ name +".png");
		int map = getentityproperty(self, "map");
		int palette = openborvariant("current_palette");
		int hres = openborvariant("hresolution");
		
		/*
		int map = getglobalvar("map");
		
		
		*/
		
		int  iETime     = openborvariant("elapsed_time");       //Current time.
    int  iMax       = openborvariant("count_entities");            //Entity count.
    int  iEntity;                                           //Loop counter.
    void vEntity;                                           //Target entity.

   for(iEntity=0; iEntity<iMax; iEntity++)
    {   
        vEntity = getentity(iEntity);                                       //Get target entity from current loop.       
       
        if (vEntity && self)                                               //Both Self and Target?
        {
            changeentityproperty(vEntity, "frozen", 0);               //Toggle frozen.
  //          changeentityproperty(vEntity, "freezetime", 15000);    //Toggle frozen time.
        }
    }
		
		
		if(getentityvar(self,0)==NULL()){
		setentityvar(self,0, health);
		}
		
		if(findtarget(P1)){
			drawbox(176,6,health,2,1800,rgbcolor(255,234,41),0);
			drawbox(176,8,health,1,1800,rgbcolor(255,226,0),0);
			drawbox(176,9,health,1,1800,rgbcolor(255,206,24),0);
			drawbox(176,10,health,1,1800,rgbcolor(246,194,0),0);
			drawbox(176,11,health,1,1800,rgbcolor(230,141,0),0);
			drawbox(176,12,health,1,1800,rgbcolor(222,92,0),0);
			changeentityproperty(self, "iconposition", 262, -121);
			drawstring(hres-27-strwidth(name, 0), 55, 0, name);
			//settextobj(findtarget(P1),hres-27-strwidth(name, 0),55,0,900000000000,name);
			//changetextobjproperty(findtarget(P1),"z",900000000000);
	//		drawsprite(icon,262,21,1800);
		}else if(findtarget(P2)){
			drawbox(100+(50-health),6,health,2,1800,rgbcolor(255,234,41),0);
			drawbox(100+(50-health),8,health,1,1800,rgbcolor(255,226,0),0);
			drawbox(100+(50-health),9,health,1,1800,rgbcolor(255,206,24),0);
			drawbox(100+(50-health),10,health,1,1800,rgbcolor(246,194,0),0);
			drawbox(100+(50-health),11,health,1,1800,rgbcolor(230,141,0),0);
			drawbox(100+(50-health),12,health,1,1800,rgbcolor(222,92,0),0);
			changeentityproperty(self, "iconposition", -56, -121);
			drawstring(33, 55, 1, name);
		//	drawsprite(icon,-56,21,1800);
		}
		
/*		if(icon){
			int iconmap = getentityproperty(icon, "map");
			int colourtable = getentityproperty(icon, "colourtable", 255);
			changedrawmethod(icon, "enabled", 1);
			changedrawmethod(icon, "remap", -1);
		}*/
		
		if(health<getentityvar(self,0)){
			if(getentityvar(self,1)==NULL()){
				setentityvar(self,1,0);
			}
			setentityvar(self,1,getentityvar(self,1)+1);
			if(getentityvar(self,1) > 50){
				setentityvar(self,0,getentityvar(self,0)-1);
				setentityvar(self,1,0);
			}
		}
	}
}

I tried using findtarget(player) (for player's opponent, the enemy type) in index section with both settextobj and changetextobj but it crashes. It don't fit enemies at all, only player index. Are there property names in both layer and textobj properties in SourceForge?

What function should/could I replace drawstring with for setlayering the string for enemies? I know index is for players.
 
Uh maxman, are you using that script as enemy's updatescript?

Also, if you're using updatescript then why not just use drawstring? As Damon Caskey posted above, drawstring and settextobj don't have advantage over each other, so using drawstring should be sufficient

Although I'm not sure the purpose of your script, I can see that you only use drawstring for displaying player's name. Since player's name is less likely to change, running settextobj to show player's name on player's SPAWN animation should be sufficient
 
No. It's not from updatescript. It's from enemy's ondrawscript based on msmalik's HP bar script.

I knew DC said about both drawstring and settextobj not taking advantage of each other. But I was curious if there's another text object function for self/entity like enemies.

The purpose for using the text object for enemies is for making the text behind so enemies can cover while jumping. You know... using the z layer. The drawstring in the script I posted is for the enemy, not the player. But I use drawstring or settextobj for player's name in update.c. It's not about players. It's about enemies. If it doesn't work, I'll have no choice but to add setlayer of the real value of 268435341 (this value is never documented for covering everything) or higher for enemies. As a result, I'll add a very higher value of setlayer for projectiles than players and enemies.
 
Back
Top Bottom