"Unexpected '{'" error while declaring a 3D array.

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
milkFiend
Posts: 27
Joined: Tue Nov 21, 2023 10:30 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: Intel (Modern GZDoom)

"Unexpected '{'" error while declaring a 3D array.

Post by milkFiend »

To summarize, I'm trying to run a script to return a number to use with A_SetTics();
However, whenever I run it in gzdoom, I get the error message:

"GUnexpected '{' Expecting '-' or '+' or '++' or '--' or '(' or identifier or string constant or integer constant or 'super' or '~' or '!' or 'sizeof' or 'alignof' or unsigned constant or float constant or name constant or 'false' or 'true' or 'null'"

I think this tells me that there's something wrong with my formatting or maybe that I can't set an array where I'm trying to set it.

The code used is as follows:

Code: Select all

Class VMMelee : Weapon
{
	//MODEL FILE
	protected name ModelName;
	property ModelFile : ModelName;
	//MELEE TYPE
	protected name MeleeType;
	property MeleeType : MeleeType;
	//ATTACK SPEED
	protected int AttackSpeed;
	property AttackSpeed : AttackSpeed;
	//BASE DAMAGE
	protected int AttackPower;
	property AttackPower : AttackPower;
	
	int GetProperTics(string MeleeType, name CurrentAction, bool isActionFrame)
	{
		// FrameCount[numberOfMeleeTypes][numberOfActionTypes][Action/EndFrame]
		int FrameCount[2][4][2] = { 
			//Stab
			{	//	!!!	!!!THIS IS THE LINE CALLED IN THE ERROR MESSAGE!!!	!!!	\\
				{57, 57}, //Idle, 57 total
				{10, 13}, //Attack, 23 total
				{16, 25}, //AltAttack, 41 total
				{0, 0} //Throw, 0 total
			},
			//Slash
			{
				{57, 57}, //Idle, 57 total
				{7, 4}, //Attack, 11 total
				{21, 5}, //AltAttack, 26 total
				{18, 6} //Throw, 24 total
			}
		};
		//CONVERT MeleeType TO MeleeIndex
		int meleeIndex= (MeleeType == "Stab") ? 0 :
			(MeleeType == "Slash") ? 1 : 2;
		//CONVERT CurrentAction TO ActionIndex
		int actionIndex = (CurrentAction == "Idle") ? 0 :
			(CurrentAction == "Attack") ? 1 :
			(CurrentAction == "AltAttack") ? 2 : 3; //3 defines "throw"
		// Return the tic value based on isActionFrame
		return FrameCount[meleeIndex][actionIndex][isActionFrame ? 1 : 0];
	}
	Default
	{
		VMMelee.ModelFile 'vm_arms.iqm';
		VMMelee.MeleeType 'Slash';
		VMMelee.AttackPower 5;
		VMMelee.AttackSpeed 1;
		+DECOUPLEDANIMATIONS
		+WEAPON.CHEATNOTWEAPON
	}
	States
	{
		//Omitted the states for the sake of brevity
	}
}
User avatar
Player701
 
 
Posts: 1694
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: "Unexpected '{'" error while declaring a 3D array.

Post by Player701 »

It looks like multidimensional array initializers are not supported in ZScript (yet), so that code is not going work. You'll have to use either one-dimensional arrays or some other method (e.g. switch statement, a tree of if-else blocks etc).
milkFiend
Posts: 27
Joined: Tue Nov 21, 2023 10:30 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: Intel (Modern GZDoom)

Re: "Unexpected '{'" error while declaring a 3D array.

Post by milkFiend »

Player701 wrote: Tue Nov 26, 2024 2:33 am It looks like multidimensional array initializers are not supported in ZScript (yet), so that code is not going work. You'll have to use either one-dimensional arrays or some other method (e.g. switch statement, a tree of if-else blocks etc).
yeah, I ended up going with a regular 1D array with an index calculation, which seems to work well.

Return to “Scripting”