problems with ftos in csqc

Discuss programming in the QuakeC language.
Post Reply
Nahuel
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

problems with ftos in csqc

Post by Nahuel »

I can not get a string in csqc to print in some csqc buttons i created.

Code: Select all

float g_tornillo;   
string s_tornillo; // a string that write a number inside the button. 

g_tornillo  = getstatf(STAT_ITEM_TORNILLO );
s_tornillo = ftos(g_tornillo);  //  doesn´t work. i also tested s_tornillo = ftos(STAT_ITEM_TORNILLO ); with no positive results


if (g_tornillo >= 1)
{
CreateButton( s_tornillo,"impulse 19\n;back",men, buttonback, but_size, 1");
}
else 
{
CreatePic( men, buttonback, but_size, 0.1); 
}
men_x = men_x + but_size_x;
i wanna to write the number of "s_tornillo" inside the button but doesn´t work.
I tested this code to redefine the string "s_tornillo" and works perfectly in the button

Code: Select all

if (g_tornillo == 1) 
s_tornillo = "1";
else if (g_tornillo == 2) 
s_tornillo = "2";
This is very stupid code, but i can say the button work. I just wanna to get the string to the number of the float "g_tornillo", but ftos doesn´t work inside my button. CSQC doesn´t write anything in my buttons. But when i define the strings it works. Any idea about it? Thanks :D
hi, I am nahuel, I love quake and qc.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: problems with ftos in csqc

Post by Spike »

ftos returns a temp string. temp strings are only valid for the duration of the qc invocation.
Specifically, this means that when you return from qc to the engine, all your tempstrings get wiped.

Try strzone and strunzone from the FRIK_FILE extension.
Nahuel
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: problems with ftos in csqc

Post by Nahuel »

Spike wrote:ftos returns a temp string. temp strings are only valid for the duration of the qc invocation.
Specifically, this means that when you return from qc to the engine, all your tempstrings get wiped.

Try strzone and strunzone from the FRIK_FILE extension.
Thanks for the request Spike, i have another question: What is the use of tokenize?
hi, I am nahuel, I love quake and qc.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: problems with ftos in csqc

Post by Spike »

tokenize splits a string into its tokens.

hello world "and anyone else that will" listen

hello
world
and anyone else that will
listen

use argv(0 to 3) to retrieve those four strings after tokenizing. The builtin itself will return the number of tokens available (4).
Seven
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Re: problems with ftos in csqc

Post by Seven »

Hello Nahuel,

Spike also explained/suggested me once, to use "tokenize" for another issue I had.
At that time I had the exact same question like you. We both speak too bad english to understand QC intuitively, Nahuel :lol:
The key words are made to be as understandable as possible without reading documentation,
except for some people from Argentinia and Germany, hehe ;)

It is interesting to see with which difficulties we both have to stuggle sometimes...
Sorry for offtopic, I just wanted to tell you this.

Best wishes Nahuel,
Seven
Post Reply