View Single Post
Author Message
DJPlaya
Senior Member
Join Date: Nov 2014
Location: Germany
Old 10-14-2019 , 15:40   Call a Function from itself?!?
Reply With Quote #1

For a Project ime currently working on, i would like to call a Function from itself (if thats possible).
I know it sounds dump, but its the most efficient and compact way todo what i want.
The idea is to bring multiply Features into one big Function so i dont have to write a Function for every Feature (especially if they only require 1-3 Lines of Code).

This is an Example of how i thought it could work, all Vars only get created when called from Outside. This is identified by iAction which carries a positive Value when beeing called from Outside and a negative Value when beeing called from Inside.
Sadly this dosent work, it seems the Compiler dosent recognize this Mechanism and spits 'undefined symbol' Errors.
Code:
#include <smlib>

public void OnPluginStart()
{
	Some_Action(1, 1, "test");
}

Some_Action(iClient, iAction, const char[] cReason, any ...)
{
	if(iAction == 0) // 0 - Do nothing
		return;
		
	if(iAction > 0) // This is a Check, negative Values mean the Function is re-run
	{
		bool bTranslated; // Its okay to leave the old Values of bTranslated and cReason, we are just not allowed to change them
	}
	
	if(!StrContains(cReason, "TRANS_"))
	{
		if(iAction > 0) // This is a Check, negative Values mean the Function is re-run // Its okay to leave the old Values of bTranslated and cReason, we are just not allowed to change them
		{
			char cReason2[256];
			VFormat(cReason2, sizeof(cReason2), cReason, 4);
		}
	}
	
	else // Is Translated
	{
		bTranslated = true;
		
		if(iAction > 0) // This is a Check, negative Values mean the Function is re-run // Its okay to leave the old Values of bTranslated and cReason, we are just not allowed to change them
			Translate(cReason, cReason2, 256);
	}
	
	if(iAction < 0) // This is a Check, negative Values mean the Function is re-run
		iAction = Math_Abs(iAction);
		
		
	if(iAction == 1)
	{
		if(!bTranslated)
			PrintToServer("test");
			
		else
			Some_Action(iClient, -2, cReason2);
	}
	
	if(iAction == 2)
		PrintToServer("test translated");
}

Translate(char[] cTranslation, char[] cDestination, iMaxlenght)
{
	// Placeholder
	strcopy(cTranslation, iMaxlenght, cDestination);
}
Someone may have an Idea how todo this? Is there maybe an forgotten Compiler Option i dont know of like 'pragma unused'?
__________________
My biggest Projects: Kigen AC Redux, Forlix Floodcheck Redux
DJPlaya is offline
Send a message via Skype™ to DJPlaya