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

New syntax troubles


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wwahgnerbp
Member
Join Date: Mar 2013
Location: Earth, Solar System
Old 04-28-2017 , 16:42   New syntax troubles
Reply With Quote #1

Hello I'm trying to transfer this to the new syntax:

Code:
stock ZMarketCookiesToArray(client, String:rebuyweapons[WeaponsSlot][], maxweapons, maxlen)
becoming:

Code:
stock void ZMarketCookiesToArray(int client, String:rebuyweapons[WeaponsSlot][], int maxweapons, int maxlen)
the problem is that I have no idea how to convert the String: tagging thing. The transitional API says that we need to specify the size if the brackets come after the variable then I try this:

Code:
stock void ZMarketCookiesToArray(int client, char rebuyweapons[WeaponsSlot][], int maxweapons, int maxlen)
where WeaponsSlot is an enum:

Code:
/**
 * Weapon slots.
 */
enum WeaponsSlot
{
	Slot_Invalid		= -1,   /** Invalid weapon (slot). */
	Slot_Primary		= 0,	/** Primary weapon slot. */
	Slot_Secondary	  = 1,	/** Secondary weapon slot. */
	Slot_Melee		  = 2,	/** Melee (knife) weapon slot. */
	Slot_Projectile	 = 3,	/** Projectile (grenades, flashbangs, etc) weapon slot. */
	Slot_Explosive	  = 4,	/** Explosive (c4) weapon slot. */
	Slot_NVGs		   = 5,	/** NVGs (fake) equipment slot. */
}
but the compiler gives me this:

error 159: brackets after variable name indicate a fixed-size array, but size could not be determined - either specify sizes, an array initializer, or use dynamic syntax (such as 'char[] x')

Is there a possibility to solve that?

Also I have another doubt.

Usually when we want to declare multiple variables with the same value we do:

int a, b, c, d; (all initialized as 0)

in the old syntax we could do this:

Code:
new targets[MAXPLAYERS], bool:tn_is_ml, result;
how can I do the same thing in the new syntax?

If I try to make it like:

Code:
int targets[MAXPLAYERS], bool tn_is_ml, result;
it won't work and the compiler suggest to use the operator view_as

I use that here:

Code:
result = ProcessTargetString(target, client, targets, sizeof(targets), COMMAND_FILTER_ALIVE, targetname, sizeof(targetname), tn_is_ml);
Any help will be appreciated.

Last edited by wwahgnerbp; 04-28-2017 at 22:00.
wwahgnerbp is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 04-28-2017 , 17:16   Re: New syntax troubles
Reply With Quote #2

You don't have to define a size (WeaponsSlot), you can do this:

PHP Code:
stock void ZMarketCookiesToArray(int clientchar[][] rebuyweaponsint maxweaponsint maxlen
and for your 2nd question you can do this:

PHP Code:
int targets[MAXPLAYERS]; bool tn_is_mlint result;
result ProcessTargetString(targetclienttargetssizeof(targets), COMMAND_FILTER_ALIVEtargetnamesizeof(targetname), tn_is_ml); 
or

PHP Code:
int targets[MAXPLAYERS], tn_is_mlresult;
result ProcessTargetString(targetclienttargetssizeof(targets), COMMAND_FILTER_ALIVEtargetnamesizeof(targetname), view_as<bool>(tn_is_ml)); 
__________________

Last edited by Chaosxk; 04-28-2017 at 17:19.
Chaosxk is offline
wwahgnerbp
Member
Join Date: Mar 2013
Location: Earth, Solar System
Old 04-28-2017 , 17:40   Re: New syntax troubles
Reply With Quote #3

I forgot to mention that rebuyweapons is declared like this:
Code:
char rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH];
Here's the full code

Code:
/**
 * Force a client to rebuy their weapons.
 * 
 * @param client	The client index.
 */
void ZMarketRebuy(int client, bool autorebuy = false)
{
	// If client is dead, then stop.
	if (!IsPlayerAlive(client))
	{
		TranslationPrintToChat(client, "Must be alive");
		return;
	}
	
	// If client is a zombie, then stop.
	if (InfectIsClientInfected(client))
	{
		TranslationPrintToChat(client, "Must be human");
		return;
	}
	
	bool zmarketbuyzone = GetConVarBool(g_hCvarsList[CVAR_WEAPONS_ZMARKET_BUYZONE]);
	if (!autorebuy && zmarketbuyzone && !WeaponsIsClientInBuyZone(client))
	{
		TranslationPrintToChat(client, "Weapons zmarket buyzone");
		return;
	}
	
	// Transfer cookie values into an array.
	char rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH];
	ZMarketCookiesToArray(client, rebuyweapons, WEAPONS_SLOTS_MAX + 1, sizeof(rebuyweapons[]));
	
	
	// x = Weapon slot.
	for (int x = 0; x < WEAPONS_SLOTS_MAX + 1; x++)
	{
		// If slot is empty, then stop.
		if (!rebuyweapons[x][0])
		{
			continue;
		}
		
		ZMarketEquip(client, rebuyweapons[x], true);
	}
}
Code:
stock void ZMarketCookiesToArray(int client, char[][] rebuyweapons, int maxweapons, int maxlen)
{
	char rebuycookiename[32];
	Handle rebuycookie;
	
	// x = Weapon slot.
	for (int x = 0; x < maxweapons; x++)
	{
		// Format cookie name.
		Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, x);
		
		// Find cookie handle, and retrieve its value.
		rebuycookie = FindClientCookie(rebuycookiename);
		GetClientCookie(client, rebuycookie, rebuyweapons[x], maxlen);
		CloseHandle(rebuycookie);
	}
}
When I try as you suggested the compiler gives me two errors but it manages to generate the binary

// zr/weapons/zmarket.inc(116 : warning 213: tag mismatch
// zr/weapons/zmarket.inc(116 : warning 229: index tag mismatch (symbol "rebuyweapons")


What does these errors means? How can I solve that?

Last edited by wwahgnerbp; 04-28-2017 at 18:20.
wwahgnerbp is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-28-2017 , 18:30   Re: New syntax troubles
Reply With Quote #4

PHP Code:
char rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH
in param definition, but anything passed to that param must match array size (or greater?)
__________________
WildCard65 is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 04-28-2017 , 18:37   Re: New syntax troubles
Reply With Quote #5

Dynamic array so gotta convert it to this:

PHP Code:
char[][] rebuyweapons = new char[WeaponsSlot][WEAPONS_MAX_LENGTH];
ZMarketCookiesToArray(1rebuyweaponsWEAPONS_SLOTS_MAX 1WEAPONS_MAX_LENGTH); 
__________________

Last edited by Chaosxk; 04-28-2017 at 18:37.
Chaosxk is offline
wwahgnerbp
Member
Join Date: Mar 2013
Location: Earth, Solar System
Old 04-28-2017 , 20:16   Re: New syntax troubles
Reply With Quote #6

that makes sense now. And I have a last question I promise

let's say we have this

Code:
KnockbackSetVelocity(client, const Float:startpoint[3], const Float:endpoint[3], Float:magnitude)
if I convert the float variables to this

Code:
void KnockbackSetVelocity(int client, const float startpoint[3], const float endpoint[3], float magnitude)
can it be also expressed like this?:

Code:
void KnockbackSetVelocity(int client, const float[3] startpoint, const float[3] endpoint, float magnitude)
Is float[3] endpoint and float endpoint[3] the same thing?

I ended up having this doubt too after reading BAILOPAN's first post from 2014 where he demonstrates us how weird would it be if we try to express this using the tagging system and the declaration rules of chars also contributed to increase my doubts

his example:
Code:
native float[3] GetEntOrigin();

Last edited by wwahgnerbp; 04-28-2017 at 20:35.
wwahgnerbp is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 04-28-2017 , 23:05   Re: New syntax troubles
Reply With Quote #7

Yes, they seem to work the same way.
__________________
Chaosxk is offline
wwahgnerbp
Member
Join Date: Mar 2013
Location: Earth, Solar System
Old 04-29-2017 , 00:32   Re: New syntax troubles
Reply With Quote #8

Quote:
Originally Posted by Chaosxk View Post
Yes, they seem to work the same way.
Alright thank you very much!
wwahgnerbp is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-29-2017 , 04:49   Re: New syntax troubles
Reply With Quote #9

No, they're different - but the difference is immaterial until SourcePawn moves further along.

float[3] foo = type is float[3], a fixed array of 3 floats, foo is a single float[3].
float bar[3] = type is float, bar is a dynamic array of 3 floats.

You almost always want the former, especially for vectors.
__________________
asherkin is offline
wwahgnerbp
Member
Join Date: Mar 2013
Location: Earth, Solar System
Old 04-29-2017 , 10:22   Re: New syntax troubles
Reply With Quote #10

Quote:
Originally Posted by asherkin View Post
No, they're different - but the difference is immaterial until SourcePawn moves further along.

float[3] foo = type is float[3], a fixed array of 3 floats, foo is a single float[3].
float bar[3] = type is float, bar is a dynamic array of 3 floats.

You almost always want the former, especially for vectors.
Alright Mr. Asher I can see now. Thank you for clarifying this.
wwahgnerbp 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 19:26.


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