Raised This Month: $ Target: $400
 0% 

[SOLVED] output Float


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gugie
Member
Join Date: Jul 2012
Old 12-24-2013 , 23:09   [SOLVED] output Float
Reply With Quote #1

Well, i found a couple of threads about how output string, but how i can output float? int? bool?

For example.
PHP Code:
SomeCommand(client)
{
    new 
Float:fl1 0.0Float:fl2 0.0Float:fl3 0.0;
    
PleaseOutput(clientfl1fl2fl3);
    
PrintToServer("New Floats: %.2f, %.2f, %.2f"fl1fl2fl3);
}

PleaseOutput(clientFloat:fl1Float:fl2Float:fl3)
{
    
fl1 float(client)*0.5;
    
fl2 fl1*6.0;
    
fl3 fl1*fl2;

So i want that command PleaseOutput return fl1, fl2 and fl3. But i want use only one command for this. So i don't need:

PHP Code:
SomeCommand(client)
{
    new 
Float:fl1 PleaseOutput1(client);
    new 
Float:fl2 PleaseOutput2(fl1); 
    new 
Float:fl3 PleaseOutput3(fl1fl2); 
    
PrintToServer("New Floats: %.2f, %.2f, %.2f"fl1fl2fl3);
}

Float:PleaseOutput1(client)
{
    return 
float(client)*0.5;
}

Float:PleaseOutput2(Float:fl1)
{
    return 
fl1*6.0;
}

Float:PleaseOutput3(Float:fl1Float:fl2)
{
    return 
fl1*fl2;

Any way to output 3 floats in one command?

Last edited by Gugie; 12-25-2013 at 09:01.
Gugie is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 12-25-2013 , 01:53   Re: output Float
Reply With Quote #2

You can use array of floats as the function argument and fill it in the process.
Or you can use datapack and, again, pass it in the arguments.

You can use array of floats as the function argument and fill it in the process.
Or you can use datapack and, again, pass it in the arguments.

PHP Code:
SomeCommand(client)
{
    
decl Float:arr[3];
    
PleaseOutput(clientarr);
    
PrintToServer("New Floats: %.2f, %.2f, %.2f"arr[0], arr[1], arr[2]);
}

PleaseOutput(clientFloat:out[3])
{
    
out[0] = float(client) * 0.5;
    
out[1] = out[0] * 6.0;
    
out[3] = out[0] * out[1];


Last edited by xf117; 12-25-2013 at 02:04.
xf117 is offline
Send a message via ICQ to xf117
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 12-25-2013 , 02:16   Re: output Float
Reply With Quote #3

https://wiki.alliedmods.net/Format_C...mat_Specifiers

PHP Code:
SomeCommand(client)
{
    
decl Float:arr[3] = 0.0;
    
PleaseOutput(clientarr);
    
PrintToServer("New Floats: %.2f, %.2f, %.2f"arr[0], arr[1], arr[2]);
}

PleaseOutput(client, &Float:Out[3])
{
    
Out[0] = float(client)*0.5;
    
Out[1] = Out[0]*6.0;
    
Out[2] = Out[0]*Out[1];

Nearly the same, but I believe you need the &ref to overwrite arr[].
__________________

Last edited by Chdata; 12-25-2013 at 02:21.
Chdata is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 12-25-2013 , 02:33   Re: output Float
Reply With Quote #4

In SP arrays are automatically passed by reference I believe. No need for &

Last edited by blaacky; 12-25-2013 at 02:33.
blaacky is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 12-25-2013 , 03:45   Re: output Float
Reply With Quote #5

Hmm. Not much need for this in sm, but what's the deal with the whole reference system? There were a few times where A ptr to ptr would have been appropriate, but instead I had to find roundabout ways of accomplishing said task. Or you know, I could just be doing it wrong, and don't know about all of the referencing/dereferencing operators in sm.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 12-25-2013 , 04:16   Re: output Float
Reply With Quote #6

Quote:
Originally Posted by friagram View Post
Hmm. Not much need for this in sm, but what's the deal with the whole reference system? There were a few times where A ptr to ptr would have been appropriate, but instead I had to find roundabout ways of accomplishing said task. Or you know, I could just be doing it wrong, and don't know about all of the referencing/dereferencing operators in sm.
There is not much to deal with. All number are passed by value, arrays and string are passed by ref.
You don't need any ref/deref operators since you never copy an object during function calling. And you don't really have any pointers either. There are handles, but they are a little bit easier to deal with.
xf117 is offline
Send a message via ICQ to xf117
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 12-25-2013 , 07:48   Re: output Float
Reply With Quote #7

Quote:
Originally Posted by Gugie View Post
So i want that command PleaseOutput return fl1, fl2 and fl3. But i want use only one command for this.
Either use the array method suggested, or use that second function in the OP, changing each Float to &Float.
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)
MasterOfTheXP is offline
Gugie
Member
Join Date: Jul 2012
Old 12-25-2013 , 09:01   Re: output Float
Reply With Quote #8

Quote:
Originally Posted by MasterOfTheXP View Post
Either use the array method suggested, or use that second function in the OP, changing each Float to &Float.
Thank you! That works great >_<
Gugie is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode