Raised This Month: $51 Target: $400
 12% 

Formatating params on the fly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 09-27-2014 , 15:08   Formatating params on the fly
Reply With Quote #1

For example, I have this function:
PHP Code:
ttt_log_to_file(typemsg[]);
usage example:
ttt_log_to_file(LOG_ERROR"Wrong param (ttt_set_winner)"); 
What I want to do is:
PHP Code:
ttt_log_to_file(LOG_ERROR"Wrong param (param=%d, val = %d) (ttt_set_winner)"1get_param(1)); 
That is just an example, I would be formatating more usefull params. Is it possible without calling formatex/format?

I can think only one way - pass as params and format it in stock/function itself, but that is not what I want, cause that limits to specific number of params, I want it more flexible..
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 09-27-2014 , 15:19   Re: Formatating params on the fly
Reply With Quote #2

You can have your function act similar to format/formatex using the vformat native:

Code:
ttt_log_to_file(type, fmt[], any:...) {    new message[256];    vformat(message, charsmax(message), fmt, 3);    /* message will now contain a string formatted according       to the format rules in fmt and the format parameters */ }
__________________
In Flames we trust!
Nextra is offline
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 09-27-2014 , 15:24   Re: Formatating params on the fly
Reply With Quote #3

:O Fast and great response, thanks. I have never used vformat, how it differs from format/formatex? Read API, but didn't understand :/
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-27-2014 , 15:27   Re: Formatating params on the fly
Reply With Quote #4

Basically the same, except last param is to set the passed arguments position index. Here you see any:... where it contains arguments is at 3rd place in the header, so you write 3.
__________________
Arkshine is offline
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 09-27-2014 , 17:46   Re: Formatating params on the fly
Reply With Quote #5

Sweet, thanks
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS 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 22:29.


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