How to set text under certain conditions

Non-platform specific questions.

How to set text under certain conditions

Postby happyjustbecause » Tue Aug 14, 2012 1:46 am

I've been using a pretty inefficient space wasting method for text in my game, I've just been making images with text rather than having a font in my data and setting text in gameEditor. I've got a large amount of text in my pause menu, and I would like to change it from an image to in game text if you know what I mean.

But for something like my upgrades menu, I have it so that if the crosshairs or mouse hover over the "button" to purchase the upgrade, text pops up. But you can switch the menu to be hosting different upgrades. So basically I need to be able to have if statements or switch statements that set the text to be a certain text depending on what menu you are at.

Do I need to have 4 different actors for the text? Or is there some way to set text in script editor? Basically what I'm asking is can text me set under certain conditions like an if statement permits, kind of like:

Code: Select all
if(Upgrades_state==2)
{
    setText(Bomb Text)
}
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: How to set text under certain conditions

Postby SuperSonic » Tue Aug 14, 2012 1:52 am

You could create one text actor and for it's draw event, you could put this:
Code: Select all
switch(Upgrades_state)
{
    case 2:
        setText(BombText);
        break;

    case etc:
        ....
}
:D

EDIT*
HappyJustBecause wrote:Basically what I'm asking is can text me set under certain conditions like an if statement permits, kind of like:
Yeah, you should be able to do that :)
Last edited by SuperSonic on Tue Aug 14, 2012 1:55 am, edited 1 time in total.
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: How to set text under certain conditions

Postby Jagmaster » Tue Aug 14, 2012 1:53 am

I know I'll get beat to this, haha

Sprintf and strcpy are used to write strings, like text.

http://game-editor.com/Sprintf
http://cplusplus.com/reference/clibrary/cstdio/sprintf/
http://cplusplus.com/reference/clibrary/cstring/strcpy/

:)

Edit: yep, and use the switch like SS along with those functions :lol: I get beat all the time xD
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: How to set text under certain conditions

Postby happyjustbecause » Tue Aug 14, 2012 2:58 am

Thank you Supersonic and Jagmaster! I overlooked the links you(Jag) sent, but I don't quite know how to set the text still... I'm not sure how to actually write just text for this:

Code: Select all
sprintf(text, "A string: %s\nAn integer: %d\nA float value: %f", "Hello!", 7, 3.4);


I thought to just put:

Code: Select all
sprintf(text, "A string: %s\nAn", "Hello!");


But I'm sure that's not correct, can you(someone) please show me an example of how to input text?
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: How to set text under certain conditions

Postby Jagmaster » Tue Aug 14, 2012 3:32 am

Sorry, I knew I should of briefed a bit more on those :? Anyway,

The difference between sprintf and strcpy is, the sprintf function can insert other variables into the string (text). Strcpy just copies one string value into annother string.
For instance:
Code: Select all
strcpy(text, "This is a whole bunch of useless text");

Text would be the variable that displays the text in the text actor, and the stuff in the quotes is the stuff we're coping into it. If you had 2 string variables that you simply wanted to copy from one to the other, you'd leave off the quotes. It is a little simpler, but not nearly as versatile as sprintf.

The sprintf has a lot of neat escape sequences that you can use to drop an actual variable into the string.
For instance:
Code: Select all
sprintf(text, "Score: %d", scorevariable);
that would display the score and the "Score:" in the same line of text. The %d is the integer escape sequence, the others are listed on the ge wiki page.

Another thing you might need would be "\n" which, when inserted, makes a new line. there are others that use the forward slash like that, but I forgot what they are, and not all of them worked in ge (I think like \t for tab or something like that).

I've had problems with text going out of the 255 character limit before, so watch out. I think I was passing the text through a string variable though, not sure it was a while ago. :lol: I'll double check to see if that's an issue.
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: How to set text under certain conditions

Postby happyjustbecause » Tue Aug 14, 2012 6:32 am

Oh thank you very much Jagmaster! I can use both the strcpy and sprintf for useful purposes! I feel like I'm back in a tutorial for the beginning of coding, seeing something like:

"This is a whole bunch of useless text"

:D

I'll begin swapping out images of text for actual text immediately. One last question (for now), so there's a 255 character limit? Is there any way to get around this? I don't need it for the thing I currently want to do, but I might want to do something with more than that.
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: How to set text under certain conditions

Postby happyjustbecause » Tue Aug 14, 2012 6:57 am

Also, I've been trying to do use the "\n" for a new line in the strcpy, but I can't figure out how to use it, when I try to I keep getting a close parenthesis error.

This is my attempt

strcpy(text, "Obsolete text"\n"New Line of Useless Text");
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: How to set text under certain conditions

Postby MrJolteon » Tue Aug 14, 2012 7:15 am

happyjustbecause wrote:Also, I've been trying to do use the "\n" for a new line in the strcpy, but I can't figure out how to use it, when I try to I keep getting a close parenthesis error.

This is my attempt

strcpy(text, "Obsolete text"\n"New Line of Useless Text");

It's
Code: Select all
strcpy(text, "Obsolete text\nNew Line of Useless Text");
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: How to set text under certain conditions

Postby happyjustbecause » Tue Aug 14, 2012 4:53 pm

Oh okay, I thought it didn't need the quotes, that they were just there so you know that it is only \n, but I didn't try it for some reason. Thank you!
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: How to set text under certain conditions

Postby Jagmaster » Tue Aug 14, 2012 7:36 pm

Just confirming the 256 char limit, which is rather annoying if have long text. One fix is to split the text into 256 char chunks and cycle through them in a keydown event. May or may not work for what you're doing.

Oddly, you can make the the startup text be as long as you want. I don't get that. :|
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: How to set text under certain conditions

Postby skydereign » Tue Aug 14, 2012 8:53 pm

The reason for that is that the startup text is predetermined in size. It can know how large to allocate the text (in fact it might just store startup text elsewhere). Since it already knows the size, the game won't have any problems. But, when you change it in game, it is a set size, and since you can't have an infinitely sized string in C, you run into the limit. What might be good is to have the text be dynamically allocated, and therefore we can use realloc. Though I believe the reason makslane didn't do that, is that with a set limit, the user is less likely to create weird crashes, and everyone experiences the same limit (easier to solve).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron