1084: Syntax error: expecting rightparen before colon? - actionscript-3

I'm new to AS3 and I'm trying to write a basic game code. So what I'm trying to do is when the enemy is at 0 hp, the output will say "you win!"
but it says "1084: Syntax error: expecting rightparen before colon" (on line 2)
here
{
if (enemyHP:Number = 0)
trace("you win!");
}
thx

You don't need to write type of enemyHP in if statement and to do right comparison between Number variables you need to write == instead of =. So finally your code should look like:
{
if (enemyHP == 0)
trace("you win!");
}

Related

Octave Function Undefined

Any idea why the following produces an error?
printf("this is my text\n");
MyFunc;
function MyFunc
printf("printing from inside function\n");
endfunction
This is the error I get (from the Command Window)
error: 'MyFunc' undefined near line 3, column 3
error: called from
function_example at line 3 column 1
Okay, I see the issue now. The function definition needs to be placed before the function call is made - as shown below.
printf("this is my text\n");
function MyFunc
printf("printing from inside function\n");
endfunction
MyFunc;

Actionscript 3 TypeError: Error #1006: value is not a function. Unable to find issue

I have been having trouble with AS3, most specifically with the "TypeError: Error #1006: value is not a function" error message. I'm an absolute beginner, but I've checked out the other stackOverflow questions related to Error #1006, and on other sites, and have been unable to find the source of my problem.
The Error appears when I try and call the newQueen function.
function newQueen(queenType):void
{
switch (queenType)
{
case 1 :
guardianLoyalty = 0;
break;
case 2 :
gathererLoyalty = 0;
break;
case 3 :
acolyteLoyalty = 0;
break;
case 4 :
vesselLoyalty = 0;
break;
default :
break;
}
queenRndTrait1 = randRange(1,queenTraitArray.length);
queenRndTrait2 = randRange(1,queenTraitArray.length);
queenTraitArray[queenRndTrait1](queenType,1);
queenTraitArray[queenRndTrait2](queenType,2);
queenRndDescription = randRange(1,queenDescriptionArray.length);
queenDescriptionArray[queenRndDescription](queenType);
queenRndName = randRange(1,queenNameArray.length);
queenNameArray[queenRndName](queenType);
}
Please tell me if there is anything else I can include to make answering this question easier : )
Edit:
var queenDescriptionArray:Array = new Array(queenDescription1);
function queenDescription1(queenType):void
{
switch (queenType)
{
case 1 :
guardianQueenDescription = "Dummy Description One";
break;
case 2 :
gathererQueenDescription = "Dummy Description One";
break;
case 3 :
acolyteQueenDescription = "Dummy Description One";
break;
case 4 :
vesselQueenDescription = "Dummy Description One";
break;
default :
break;
}
}
I was calling the function like newQueen(1);
Edit 2, Solved:
Thanks, null!
I had solved this problem before it arose in other parts of my program, I couldn't figure out what was different about this function!(Since I'm new, I try not to copy and paste, even my own code)
The solution was to add a "-1" to the end of the randomization lines, like so:
queenRndTrait1 = randRange(1,queenTraitArray.length)-1;
Update:
You pass 1 as the first argument to your function creating the random index.
Arrays indices start at 0.
These lines are probably causing the error:
queenTraitArray[queenRndTrait1](queenType,1);
queenTraitArray[queenRndTrait2](queenType,2);
queenDescriptionArray[queenRndDescription](queenType);
queenNameArray[queenRndName](queenType);
They have a common pattern.
You are accessing arrays here, nothing wrong with that:
array[index];
This will retrieve the element at index.
Now here comes the possible problem: you add parenthesis after that:
array[index](someStuff);
Parenthesis are use to call functions, which is ok and works fine as long as the element of the array at that index is a function.
But apparently the array element is not a function, as the error tells you.
It's unclear what you are trying to accomplish, but the problem is very likely caused by the misuse of some operators (like parenthesis)

AS3 syntax compile errors - expecting semicolon before rightparen

I know this is extremely basic but the following function is generating 2 syntax errors on compile, these are shown below. I can't figure them out. Any help is much appreciated.
Game, Layer 'Actions', Frame 2, Line 5 1086: Syntax error: expecting semicolon before rightparen.
Game, Layer 'Actions', Frame 2, Line 5 1084: Syntax error: expecting rightbrace before semicolon.
function fl_TouchEndHandler_2(event:TouchEvent):void {
// Drag & drop stuff...
contained[i] = Gem1_MC.hitTestObject(Gem4_MC));
contained[i] = Gem2_MC.hitTestObject(Gem4_MC));
contained[i] = Gem3_MC.hitTestObject(Gem4_MC));
if (contained.indexOf(false) == -1) { // This returns -1 if it can't find false
gotoAndStop(1);
}
}
You have extra ')'
try:
function fl_TouchEndHandler_2(event:TouchEvent):void {
// Drag & drop stuff...
contained[i] = Gem1_MC.hitTestObject(Gem4_MC);
contained[i] = Gem2_MC.hitTestObject(Gem4_MC);
contained[i] = Gem3_MC.hitTestObject(Gem4_MC);
if (contained.indexOf(false) == -1) { // This returns -1 if it can't find false
gotoAndStop(1);
}
}

Nonsensical TypeError: Error #1010: A term is undefined and has no properties

I have this simple code:
...
for (var w:Number=0; w < MAX_w; w++){
for (var k:Number=0; k < MAX_k; k++){
trace("test01");
if(w != k){
trace("test02");
///do sth...
}
}
}
...
And output is:
...
test01
TypeError: Error #1010: A term is undefined and has no properties.
at NS_fla::MainTimeline/vzdalenosti_bodu()
at NS_fla::MainTimeline/hlaska_zmacknul_sem()
...
Please suspects anybody what cause this problem?
Thx for answer.
If it only traces "test01" once, then the problem would not be from whatever is in the if(w!=k) scope, because the first time w=k=0. If your MAX_w and MAX_k are 0 then the problem would be coming from after the loop. In any case, the problem is not with w or k, and I think more code is needed in order to solve this issue.
BTW: Why Number and not int?
According to Run-time errors reference:
This error can occur if you are trying to access a property of an object that does not exist.
For example:
var obj:Object = new Object();
obj.a = "foo";
trace(obj.b.prop);
You can also see this error because of a mispelling, for example in the following, where mc represents a MovieClip object on the display list, and the stage property is misspelled with a capital S (it should be stage):
trace(mc.Stage.quality);
All errors are here - http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/runtimeErrors.html

AS3 Compiler error 1083: problem with else syntax

I'm creating a simple click and scroll for a future menu for my personal site. I have a box, I called it thing_mc, and I have 3 positions for it. I have a next and prev. button that will control thing_mc position. I'm using TweenLite to animate thing_mc, if that makes a difference.
I get a 1083 error (...else is unexpected) and (...rightparen is unexpected).
Can anyone tell me why and how I can resolve this?
Thanks
import gs.TweenLite;
next_mc.addEventListener(MouseEvent.CLICK, nextListener);
prev_mc.addEventListener(MouseEvent.CLICK, prevListener);
//prev_mc.visible = false;
function nextListener(event:MouseEvent):void
{
if(thing_mc.x == 400);
{
TweenLite.to(thing_mc, .5, {x:50, y:50});
}
else if //// i get error 1083 here (...else is unexpected)
{
TweenLite.to(thing_mc, .5, {x:-100, y:50}); //// i get error 1083 here (...rightparen is unexpected)
}
}
function prevListener(event:MouseEvent):void
{
if(thing_mc.x == -100);
{
TweenLite.to(thing_mc, .5, {x:400, y:50});
}
else if //// i get error 1083 here (...else is unexpected)
{
TweenLite.to(thing_mc, .5, {x:500, y:50}); //// i get error 1083 here (...rightparen is unexpected)
}
}
next_mc.buttonMode = true;
prev_mc.buttonMode = true;
I am not AS expert, but the semicolon after if(thing_mc.x == 400); and if(thing_mc.x == -100); seems strange. Should rather read if(thing_mc.x == 400) and if(thing_mc.x == -100) I'd say.
else if //// i get error 1083 here (...else is unexpected)
You have a few options here. You can either use a second condition, if you want to use else if i.e.
else if (someCondition) { ...
or, use just else
else { ...
or use another if
if { ...
It all depends on what you want to achieve.
From what I can see, the second option (plain else) looks like what you want.
function nextListener(event:MouseEvent):void
{
if(thing_mc.x == 400);
{
Don't use ; after the if brackets
;-)
Wats going on is the parser sees
if ( cond ) ;
as
if ( cond ) /empty statement/ ; //semicolon ends empty statement
(and the else if /.../ of course lacked the parenthesized conditional expr that an if requiress).
I've seen this semicolon related error a lot.
It may be because semicolons are optional in some cases in as3.