# combat grid

**URL:** https://discussions.unity.com/t/combat-grid/494570
**Category:** Scripting
**Tags:** Scripting
**Created:** [January 10, 2013, 2:39am UTC](https://discussions.unity.com/t/combat-grid/494570 "2013-01-10T02:39:03Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jtcc34](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/jtcc34/32/552958_2.png) [@jtcc34](https://discussions.unity.com/u/jtcc34)
#### Post date: [January 10, 2013, 2:39am UTC](https://discussions.unity.com/t/combat-grid/494570/1 "2013-01-10T02:39:03Z")

</div>

so I made a combat script that has both the enemy’s and the main character and his party. with also the battle layout  
but its giving me errors tell me what I am doing wrong here.

```auto
var Jake : CharacterAtt;
var block : Vector2;
var combatPosition : Vector3[] = new Vector3[6];

enum CombatPos
{
	Playerleft = 0,
	Playercenter = 1,
	Playerright = 2,
	Enemyleft = 3,
	Enemycenter = 4,
	Enemyright = 5

}

function Start () {

	for(var i : int = 0;i < 6;i++)
	{
		if(i< 3)combatPosition[i] = Vector3(transform.position.x +((i-((i<3)?1))*block.x),0,transform.position.z-(((i<3)?1)*block.y);
		else combatPosition[i] = Vector3(transform.position.x +((i-((i<3)?4)*block.x)),0,transform.position.z+(((i<3)?1)*block.y));
	
	}

	Jake = new CharacterAtt(Player.Jake,"Jake",20,21,19,18,22,22,23,1000);
	Jake.Addweapon(new Weapon("knife",1,10,false,Element.physical,50,Player.Jake));

}

```

---

<div class="post-metadata">

### Author: ![mamoniem](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/mamoniem/32/485468_2.png) [@mamoniem](https://discussions.unity.com/u/mamoniem)
#### Post date: [January 10, 2013, 2:49am UTC](https://discussions.unity.com/t/combat-grid/494570/2 "2013-01-10T02:49:20Z")

</div>

can you put the error, it will be helpful !

i guess there is messing “)” in line 21 and/or 22

m;

---

<div class="post-metadata">

### Author: ![jtcc34](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/jtcc34/32/552958_2.png) [@jtcc34](https://discussions.unity.com/u/jtcc34)
#### Post date: [January 10, 2013, 3:04am UTC](https://discussions.unity.com/t/combat-grid/494570/3 "2013-01-10T03:04:11Z")

</div>

here are the errors: expecting ), found ‘block’., ‘;’ expected. Insert a semicolon at the end., expecting ), found ‘\*’. and the rest are just like these errors so can some one tell me what I should do for my combatgrid? the max count is  
six so three tiles for the player and three tiles for enemies. here is my new code:

```auto
var Jake : CharacterAtt;
var block : Vector2;
var combatPosition : Vector3[] = new Vector3[6];

enum CombatPos
{
	Playerleft = 0,
	Playercenter = 1,
	Playerright = 2,
	Enemyleft = 3,
	Enemycenter = 4,
	Enemyright = 5

}

function Start () 
{

	for(var i : int = 0;i < 6;i++)
	{
		if(i< 3)combatPosition[i] = Vector3(transform.position.x +((i-((i<3)?1))*block.x),0,transform.position.z-(((i<3)?1)*block.y));
		else combatPosition[i] = Vector3(transform.position.x +((i-((i<3)?4)*block.x)),0,transform.position.z+(((i<3)?1)*block.y));
	
	}

	Jake = new CharacterAtt(Player.Jake,"Jake",20,21,19,18,22,22,23,1000);
	Jake.Addweapon(new Weapon("knife",1,10,false,Element.physical,50,Player.Jake));

}

```

---

<div class="post-metadata">

### Author: ![jtcc34](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/jtcc34/32/552958_2.png) [@jtcc34](https://discussions.unity.com/u/jtcc34)
#### Post date: [January 10, 2013, 8:16pm UTC](https://discussions.unity.com/t/combat-grid/494570/4 "2013-01-10T20:16:00Z")

</div>

any help would be great

---

<div class="post-metadata">

### Author: ![Aldo](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Aldo](https://discussions.unity.com/u/Aldo)
#### Post date: [January 10, 2013, 8:41pm UTC](https://discussions.unity.com/t/combat-grid/494570/5 "2013-01-10T20:41:51Z")

</div>

Sorry but your formula is coded just wrong  
all the errors are sintax errors and we dont really know what you are trying to do with that

I recomend you to rewrite it and try to use 8 or 10 lines at

```auto
   if(i< 3)combatPosition[i] = Vector3(transform.position.x +((i-((i<3)?1))*block.x),0,transform.position.z-(((i<3)?1)*block.y));

        else combatPosition[i] = Vector3(transform.position.x +((i-((i<3)?4)*block.x)),0,transform.position.z+(((i<3)?1)*block.y));

```

instead of 2 because you are trying to make too much stuff and not even you know where it came back wrong

---

<div class="post-metadata">

### Author: ![jtcc34](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/jtcc34/32/552958_2.png) [@jtcc34](https://discussions.unity.com/u/jtcc34)
#### Post date: [January 10, 2013, 11:16pm UTC](https://discussions.unity.com/t/combat-grid/494570/6 "2013-01-10T23:16:36Z")

</div>

I should say how should it look then at those two lines and this is in java

---

<div class="post-metadata">

### Author: ![jtcc34](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/jtcc34/32/552958_2.png) [@jtcc34](https://discussions.unity.com/u/jtcc34)
#### Post date: [January 14, 2013, 11:34pm UTC](https://discussions.unity.com/t/combat-grid/494570/7 "2013-01-14T23:34:52Z")

</div>

I have my combat scene all hooked up I and is working when I hit play. Now I am on my command menu and have my basic  
attack animation ready and he can give damage to the enemy but it looks like a ranged attack when it should be melee attack.  
it also gives me this error when I hit play:  
The variable Knife of ‘JakeAnimateC’ has not been assigned.  
You probably need to assign the Knife variable of the JakeAnimateC script in the inspector.  
UnityEngine.Object.Internal\_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:44)  
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:53)  
JakeAnimateC+$AttackTarget$34+$.MoveNext () (at Assets/Scripts/movement/JakeAnimateC.js:37)

so here is the script too

```auto
#pragma strict

var Knife : Transform;
var attackcomplet:boolean = false;
var Knifepoint;
var myCombatC:CombatC;

function Start()
{

	for(var child: Object in transform)
	{
		if((child as Transform).name == "knifepoint")Knifepoint = (child as Transform).position;
		
		
	}

}

function AttackTarget(myId:BaseStats,targetId:BaseStats)
{
		
	var initialRotation:Quaternion = transform.rotation;
	var targetRotation:Quaternion = Quaternion.LookRotation(targetId.myInstance.position - transform.position);
	var delta : float = 0.0;
	while(delta<1.0)
	{
		delta += Time.deltaTime;
		transform.rotation=Quaternion.Slerp(initialRotation,targetRotation,delta);
		transform.eulerAngles.x=0.0;
		transform.eulerAngles.z=0.0;
		yield;
		
	}
	
	var thisknife:Transform = Instantiate(Knife,Knifepoint,transform.rotation);
	transform.Translate(transform.forward*10*Time.deltaTime);
	animation.Play("attack");
	yield;
	while(!attackcomplet)yield;
	attackcomplet = false;
	 yield Addeffect((myId as CharacterAtt).Attack(targetId as NPCAtt),targetId.myInstance);
	delta = 0.0;
	while(delta<1.0)
	{
		delta += Time.deltaTime;
		transform.rotation = Quaternion.Slerp(targetRotation,initialRotation,delta);
		transform.eulerAngles.x =0.0;
		transform.eulerAngles.z=0.0;
		yield;
	
	
	
	}
}

function Addeffect(attackoutput:Attackoutput,Target:Transform)
{
	switch(attackoutput.result)
	{
		case Attackresult.Miss:
		Target.position.x +=1.0;
		yield WaitForSeconds(1.0);
		Target.position.x -=1.0;
		break;
		
	
	}

}

```

this code dose work and It animates my Jake character properly

---

<div class="post-metadata">

### Author: ![jtcc34](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/jtcc34/32/552958_2.png) [@jtcc34](https://discussions.unity.com/u/jtcc34)
#### Post date: [January 15, 2013, 1:31am UTC](https://discussions.unity.com/t/combat-grid/494570/8 "2013-01-15T01:31:34Z")

</div>

ok I look over my code and I forgot to add Vector3 to Knife but it still shows the same error. Oh and Ignore the very top question  
and here is the new code:

```auto
var Knife:Transform;
var attackcomplet:boolean = false;
var Knifepoint:Vector3;
var myCombatC:CombatC;

function Start()
{

	for(var child: Object in transform)
	{
		if((child as Transform).name == "knifepoint")Knifepoint = (child as Transform).position;
		
		
	}

}

function AttackTarget(myId:BaseStats,targetId:BaseStats)
{
		
	var initialRotation:Quaternion = transform.rotation;
	var targetRotation:Quaternion = Quaternion.LookRotation(targetId.myInstance.position - transform.position);
	var delta : float = 0.0;
	while(delta<1.0)
	{
		delta += Time.deltaTime;
		transform.rotation=Quaternion.Slerp(initialRotation,targetRotation,delta);
		transform.eulerAngles.x=0.0;
		transform.eulerAngles.z=0.0;
		yield;
		
	}
	
	var thisknife:Transform = Instantiate(Knife,Knifepoint,transform.rotation);
	transform.Translate(transform.forward*10*Time.deltaTime);
	animation.Play("attack");
	yield;
	while(!attackcomplet)yield;
	attackcomplet = false;
	 yield Addeffect((myId as CharacterAtt).Attack(targetId as NPCAtt),targetId.myInstance);
	delta = 0.0;
	while(delta<1.0)
	{
		delta += Time.deltaTime;
		transform.rotation = Quaternion.Slerp(targetRotation,initialRotation,delta);
		transform.eulerAngles.x =0.0;
		transform.eulerAngles.z=0.0;
		yield;
	
	
	
	}
}

function Addeffect(attackoutput:Attackoutput,Target:Transform)
{
	switch(attackoutput.result)
	{
		case Attackresult.Miss:
		Target.position.x +=1.0;
		yield WaitForSeconds(1.0);
		Target.position.x -=1.0;
		break;
		
	
	}

}

```

so Ignore this post I just answered my own Question
