How to put the value of a globalvar in the screen

dcelso

Member
Hi, I have done a golbalvar called knives,
I want to put in the screen teh value like lives, for example: knives x3 (where 3 is the value of the var)
what alternatives are there?
I have read using drawstring, but puts that that method is costly.
 
It's not as costly as you think... internally that's how the engine draws any text.

It also happens to be the only way outside of gameplay to draw custom text.

During gameplay (when in a level) there's a second option called text objects. They still use the same internal code, but are more convenient for you because they're "fire and forget". Turn the text on and it stays until you turn it off.

DC
 
ty.
I'm trying to use drawstring.
I can't get showing the text without blinking.
I can see knives : 30, and if I press attack button I can see 29, 28, etc.
but the text is blinking continously.
How can I do something like "experience variable" does?
 

Attachments

Hmmm... I found this in Kula.txt:
@script
int knives = getglobalvar("knives");
if (isempty(knives)){
knives = 30;
setglobalvar("knives",knives);
}
char text1 = "knives: " + knives;
drawstring(100, 100, 1, text1);
@end_script

That's from her header.

since you already put it there, modify it into this:
Code:
script    @script
void main()
{
  int knives = getglobalvar("knives");
  if (isempty(knives)){
    knives = 30;
    setglobalvar("knives",knives);
  }
  char text1 = "knives: " + knives;   

  drawstring(100, 100, 1, text1);
}
@end_script
 
ty, but it continues blinking, lower but continues.
I did that the manual puts so I did not created a main function.
 

Attachments

  • EntityEvents.png
    EntityEvents.png
    27.7 KB · Views: 0
ty, but it continues blinking, lower but continues.
I did that the manual puts so I did not created a main function.
if I put that code in the main of te update.c it works perfectly, does not blinks. but, the information is in the screen always. I want that hava same behavior that the player experience or lives or magic, that appears when the player enter in game and dissapears when the player leaves the game. I need repeat it for the four players. :)
 
You should've created main function as I suggested before. But since you're using update.c, you can forget that :sneaky:
Though I suggest moving this variable setting
Code:
int knives = getglobalvar("knives");
 if (isempty(knives)){
    knives = 30;
    setglobalvar("knives",knives);
  }

to player's SPAWN animation or onspawnscript.

I want that hava same behavior that the player experience or lives or magic, that appears when the player enter in game and dissapears when the player leaves the game. I need repeat it for the four players. :)

You'd need something like this in your update.c
Code:
  if(openborvariant("in_level")==1){
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");
    void P3 = getplayerproperty(2, "entity");
    void P4 = getplayerproperty(3, "entity");

    if(P1){
// declare drawstring for player 1 here
    }
    if(P2){
// declare drawstring for player 2 here
    }
    if(P3){
// declare drawstring for player 3 here
    }
    if(P4){
// declare drawstring for player 4 here
    }
  }

Well, you could declare other functions for each player in each section there. I only mention drawstring for example :)
 
Back
Top Bottom