Raised This Month: $ Target: $400
 0% 

Multiple function arguments


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
orglee
Member
Join Date: Dec 2005
Old 06-03-2009 , 15:17   Multiple function arguments
Reply With Quote #1

Hello. I'm wondering, is there a way to create function which amounts of arguments depends on how that function is called. For instance a function like format() that can take 3 arguments 4, 5 etc...
orglee is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-03-2009 , 15:38   Re: Multiple function arguments
Reply With Quote #2

Something like if I'm right and understand your question :

Code:
MyFunction( const Text[], any:... ) {     new NewText[ 128 ];     vformat( NewText, charsmax( NewText ), Text, 2 );         // }

eg : MyFunction( "Hello %s ! Today %d %c %d - %f", "world", 21, ':', 38, 2009.0 );

will look :
Code:
NewText = Hello world ! Today 21 : 38 - 2009.000000
__________________

Last edited by Arkshine; 06-03-2009 at 15:45.
Arkshine is offline
orglee
Member
Join Date: Dec 2005
Old 06-03-2009 , 16:16   Re: Multiple function arguments
Reply With Quote #3

Thank you. And what if I don't know approximate length of a Text.

Can I determine it somehow and create array appropriate for that string? Lengths of strings I would be using with that function can vary on different conditions. If I would adjust array length to longest string it would be simply a waste of server resources.

edit>
Thats what I'm trying to do

Code:
public Handle:SQLQueryCreate(const sQuery[], any:...) {     new sText[1024]         vformat(sText, strlen(sQuery), sQuery, 2);         log_amx("[CLIMB][STATS][QUERY] %s", sText)         return SQL_PrepareQuery(g_SqlConnection, sText) }

Last edited by orglee; 06-03-2009 at 16:31.
orglee is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-03-2009 , 16:35   Re: Multiple function arguments
Reply With Quote #4

public Handle:SQLQueryCreate(

Since your return an Handle type, you have to tag your function with Handle.

Also, use sizeof not strlen. charsmax is macro from amxx 1.8.x which is : ( sizeof %1 - 1 )
__________________

Last edited by Arkshine; 06-03-2009 at 16:40.
Arkshine is offline
orglee
Member
Join Date: Dec 2005
Old 06-03-2009 , 16:43   Re: Multiple function arguments
Reply With Quote #5

Yeah I figured it out myself a while after editing. ;P

And what about that array issue? As you see I've declared sText 1024 long and I'm really not sure it would be enough. I hope there is a way to create string with dynamic length.
orglee is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-03-2009 , 16:47   Re: Multiple function arguments
Reply With Quote #6

Not possible AFAIK. I'm sure you can determine a max.
__________________
Arkshine is offline
orglee
Member
Join Date: Dec 2005
Old 06-03-2009 , 17:34   Re: Multiple function arguments
Reply With Quote #7

Well to bad, but I was about to change that function to normal SQL_PrepareQuery() anyway after I'll finish debuging. - Or not if you can tell me how to check if plugin is in debuging mode ( "plugin.amxx debug" in plugins.ini ) or not.

I still have two problems that are not especially connected to this topic, but those are probably caused by my stupid mistakes so I think they don't deserve another topic.

So here it goes:
1. Weird number is being inserted/fetched to/from database.
Code:
new iPlayerID new Handle:InsertQuery_1, Handle:InsertQuery_2, Handle:InsertQuery_3 InsertQuery_1 = SQLQueryCreate("INSERT INTO `stats_player`(`sp_steamid`, `sp_lastseen`) VALUES('%s', NOW())", sAuthid) if(!SQL_Execute(InsertQuery_1)) { SQLQueryError(InsertQuery_1, "Unable to insert new player"); } InsertQuery_2 = SQLQueryCreate("SELECT `sp_id` FROM `stats_player` WHERE `sp_steamid` = '%s'", sAuthid) if(!SQL_Execute(InsertQuery_2)) { SQLQueryError(InsertQuery_2, "Unable to retrive inserted player id"); } SQL_ReadResult(InsertQuery_2, 0, iPlayerID) InsertQuery_3 = SQLQueryCreate("INSERT INTO `stats_player_names`(`spn_name`, `spn_timesused`, `_sp_id`) VALUES('%s', 1, %i)", sPlayerName, iPlayerID) if(!SQL_Execute(InsertQuery_3)) { SQLQueryError(InsertQuery_3, "Unable to insert player nickname"); }
It creates two fallowing queries:
Code:
SELECT `sp_id` FROM `stats_player` WHERE `sp_steamid` = 'STEAM_0:1:12257932'
INSERT INTO `stats_player_names`(`spn_name`, `spn_timesused`, `_sp_id`) VALUES('ajt', 1, 1096810496)
I tried to use SQL_GetInsertId () and event "SELECT LAST_INSERT_ID()" but it wasnt working at all, thats why I'm using "SELECT"

Where first query is ok, second one is far from it as third value ( _sp_id ) I should get 14. What is going on?

2. To write players map time I want to use forwarding methods.
Code:
new iReturn, iForward = CreateMultiForward("hndl_ClimbCounterStop",ET_IGNORE,FP_CELL) if(iForward < 0) { log_amx("[CLIMB][ERROR] Unable to create forward."); } if(!ExecuteForward(iForward,iReturn,id-1,timer[id-1][TMR_BSTTME])) {     log_amx("[CLIMB][ERROR] Unable to execute forward.") }   DestroyForward(iForward)
Code:
[AMXX] Run time error 10: native error (native "ExecuteForward")
edit>
Damn wrong button - still writing
edit>>
I think I'm done writing... sorry...

Last edited by orglee; 06-03-2009 at 17:45.
orglee is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-03-2009 , 17:37   Re: Multiple function arguments
Reply With Quote #8

How did you create the iPlayerID variable?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
orglee
Member
Join Date: Dec 2005
Old 06-03-2009 , 18:13   Re: Multiple function arguments
Reply With Quote #9

new iPlayerID
new Float:fPlayerID
new sPlayerID[12]

In first two cases result is the same ( 1096810496 )
When i tried retrieving id as string "SQL_ReadResult(InsertQuery_2, 0, sPlayerID, 11) i got 49 as id.
orglee is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-03-2009 , 18:24   Re: Multiple function arguments
Reply With Quote #10

Do you mind showing the full code for this function?
Also, are you using SQLx? Because I've never seen the SQLQueryCreate() function.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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:53.


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