Author Topic: Displaying Values in a Client Message  (Read 1864 times)

Very simple request:

Tell me what I'm doing wrong here. This is frustrating me.
So, something like this,
Code: [Select]
    messageClient(%client, '', '\c2\%a + \%b = \%c');I tried this too:
Code: [Select]
    messageClient(%client, '', '\c2%a + %b = %c');It would just print "a + b = c"
I would like it to display the variables instead of a, b, and c.
« Last Edit: September 24, 2012, 06:13:13 PM by Subpixel »

Code: [Select]
messageClient(%client, '', "\c2" SPC %a SPC "+" SPC %b SPC "="  SPC %c);
SPC adds a space in between two strings and @ just concatenates them. For example, echo("hello" SPC "there"); would echo hello there while echo("hello" @ "there"); would echo hellothere. You can use variables with these like I showed above.


%somevariable = 24;
%another = 3;
echo("some variable and another is equal to" SPC %somevariable @ %another);
>> some variable and another is equal to 243
« Last Edit: September 24, 2012, 08:47:02 PM by Scars75 »

If you want to have it add them up, then do messageClient(%client, '', "\c2" SPC %a SPC "+" SPC %b SPC "="  SPC %a + %b);
if not, use the above solution.

Or, messageClient(%client,'','%1 + %2 = %3', %a,%b,%c);

Or, messageClient(%client,'','%1 + %2 = %3', %a,%b,%c);
no, that won't work, but I'd like to know, is there a string format function for torquescript like there is for java? for example, you could do this in java:
Code: [Select]
System.out.printf("You have %d dollars and %02d cents", dollars, cents);
if dollars was 12 and cents was 4, it would print out "You have 12 dollars and 04 cents"
is there a function like this in torquescript?

no, that won't work, but I'd like to know, is there a string format function for torquescript like there is for java? for example, you could do this in java:
Code: [Select]
System.out.printf("You have %d dollars and %02d cents", dollars, cents);
if dollars was 12 and cents was 4, it would print out "You have 12 dollars and 04 cents"
is there a function like this in torquescript?
Maybe you should have tried it before saying it won't work, seeing as the thing you're looking for is what HellsHero just said. There is no type casting because Torque is not statically typed, but most message systems support the basic string formatting HellsHero mentioned. AFAIK, centerPrint, bottomPrint, messageClient and a few others work for it. There is no general function to format a string, though.

no, that won't work,
love how you jump to such conclusions so fast without even knowing for sure. Think before you post

Maybe you should have tried it before saying it won't work
I actually did, but I guess messageclient didn't work because I don't have my key here on my laptop. I'm not sure why it would use single quotes, but okay?

Edit: I did some more testing with center print and echo. Adding additional arguments to echo just adds them to the end of the string and any arguments in centerprint after the amount of time for the message to appear seem to do nothing. It doesn't work. I mentioned java's string formatting because I knew that was basically what he was tying to do.
« Last Edit: September 24, 2012, 10:11:44 PM by Scars75 »

You guys were too slow, I figured it out myself yesterday :P
Code: [Select]
     messageClient(%client, '', '\c2\%1 + \%2 = \%3', %a, %b, %c);

There's no need for the backslashes on %1, %2, and %3 just an fyi

looks like it does work, but only with messageclient. why haven't I seen anyone use this before? also, is it possible to do something like this in torquescript?
Code: [Select]
public static double average(double... nums){  //takes however many arguments are passed in and stores them in the array nums
double total = 0;
for(double d : nums)  //loops through the nums array and stores the value of each index in d, basically the same thing as using "for(int i = 0; i < nums.length; i++)" and storing nums[i] in d
total += d;
return total/nums.length;
}
« Last Edit: September 25, 2012, 05:39:45 PM by Scars75 »

You guys were too slow, I figured it out myself yesterday :P
Code: [Select]
     messageClient(%client, '', '\c2\%1 + \%2 = \%3', %a, %b, %c);
What is the %abc supposed to do

What is the %abc supposed to do
just placeholder variable names to show what he's doing. %1 is replaced with the second argument, %2 with the 3rd, and so on.

just placeholder variable names to show what he's doing. %1 is replaced with the second argument, %2 with the 3rd, and so on.
Wait, does that actually work?