View previous topic :: View next topic |
Author |
Message |
RooT

Joined: 07 Sep 2005 Posts: 40
|
Posted: Wed Sep 07, 2005 2:21 am Post subject: centerprint help |
|
|
hey wondering if anyone could help me, i want to centerprint a message but have it change depending on a variable, is this possible without just making if statements and every possible text variation?... let me word this better. my mod contains the ability to upgrade a class-type charactoristic (mage, robot, alien...) and you can upgrade with whichever you prefer to use at the time of upgrade. so when your experience points have reached the next level, and the menu comes up to choose the next ability you wouid like, the menu reflects your current upgrades and the next level of that upgrade.
ex:
local string skill1text, skill2text;
if (self.skill1 == 1)
{
sskill = "mage level 1: power to bargain with car dealers"
}
if (self.skill2 == 1)
{
sskill = "squirell level 1: climb trees"
}
if (self.skill2 == 2)
{
sskill = "squirell level 2: eat my nuts"
}
// then while the menu is open...
centerprint(self," MENU!\n" , skill1text , skill2text, "=====\n");
};
hope someone gets what im saying and has an answer that will make me happy
thanks-
root one _________________ My mod site!
Mod Status:
Turret Defense: 30%
UPS: 45% |
|
Back to top |
|
 |
Sajt
Joined: 16 Oct 2004 Posts: 1026
|
Posted: Thu Sep 08, 2005 2:02 am Post subject: |
|
|
If you're using FrikQCC or FTEQCC as compiler, you can open up defs.qc and replace the centerprint definition with:
void(entity client, string s, ...) centerprint = #73;
This will allow you to include up to 7 strings in a row in the centerprint command. (because builtin functions have a limit of 8 arguments)
If you're using an older compiler, replace centerprint in defs.qc with:
void(entity client, string s) centerprint = #73;
void(entity client, string s1, string s2) centerprint2 = #73;
void(entity client, string s1, string s2, string s3) centerprint3 = #73;
void(entity client, string s1, string s2, string s3, string s4) centerprint4 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5) centerprint5 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5, string s6) centerprint6 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5, string s6, string s7) centerprint7 = #73;
And use the appropriate one based on how many arguments you need.
If you need more than 7 different strings put together, there are further ways to do it, but they are hacky and will only be explained to you if you really need them  _________________ F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe. |
|
Back to top |
|
 |
Wazat
Joined: 15 Oct 2004 Posts: 732 Location: Middle 'o the desert, USA
|
Posted: Thu Sep 08, 2005 1:52 pm Post subject: |
|
|
Remember that you can only have 1 ftos in each print, or the last one will override all the ones before it. If you need more, I recommend you use Darkplaces because it has strcat and string zones to get around that problem. _________________ When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work. |
|
Back to top |
|
 |
RooT

Joined: 07 Sep 2005 Posts: 40
|
Posted: Thu Sep 08, 2005 8:56 pm Post subject: coud you explain? |
|
|
wazat what do you mean i can only have one ftos? this wouldnt work?:
if (self.showtext)
{
local string t1, t2, t3;
t1 = ftos(self.inside);
t2 = ftos(self.3d);
t3 = ftos(self.rules);
centerprint5(self, "You know what?\n", t1, t2, t3);
that would work i thought? _________________ My mod site!
Mod Status:
Turret Defense: 30%
UPS: 45% |
|
Back to top |
|
 |
Wazat
Joined: 15 Oct 2004 Posts: 732 Location: Middle 'o the desert, USA
|
Posted: Fri Sep 09, 2005 12:08 am Post subject: Re: coud you explain? |
|
|
RooT wrote: |
t1 = ftos(self.inside);
t2 = ftos(self.3d);
t3 = ftos(self.rules);
centerprint5(self, "You know what?\n", t1, t2, t3);
|
Unfortunately that won't work.
The problem is that ftos puts the string in a buffer. All strings in QC are actually just pointers to some memory location that's holding the string. Constant strings (s1 = "bleh") are always fine; however, when you say t1 = ftos(self.inside), t1 is pointing to ftos's buffer.
What this all means is, if I set t1 to point to the ftos buffer (asking ftos to convert a number in the process), then convert one or two more numbers, t1-t3 will all have the same value, because each call to ftos just overwrites what's in the buffer at the moment.
Thus, if self.rules is 10, your centerprint will print:
Quote: | You know what?
10 10 10 |
The reason sprints work so well with this is, you call ftos, and then sprint it out. Then you call ftos again and sprint it out:
Code: | s = ftos(a1);
sprint(a1);
s = ftos(a2);
sprint(a2);
s = ftos(a3);
sprint(a3); |
Thus, the number is printed and properly used before ftos erases and writes over it.
The best way around this for centerprints is to use strcat() or string zones, both of which usually come together and are provided by new engines like Darkplaces. _________________ When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work. |
|
Back to top |
|
 |
RooT

Joined: 07 Sep 2005 Posts: 40
|
Posted: Fri Sep 09, 2005 12:28 am Post subject: ahh damn |
|
|
ah shit well very informative, thank you for explaining. i sorta understand what you mean hah but ok ill hafta look into the strcat() thingy, thanks hopefuly i get this without begging you guys for too much help
-Root one _________________ My mod site!
Mod Status:
Turret Defense: 30%
UPS: 45% |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2004 phpBB Group
|