• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Issue with my script

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
//zinc

This script is for a tower called 'Time Tower'

Each minute of the game this tower is alive it will gain more damage, and if it's killed and remade/created for the first time it's damage will start at 0.

So my goal is to store when the tower was created in the integer array 'timeTower_time'
Set that to 0 when it's destroyed/first created, and add +1 every minute it's alive.

I set the boolean array 'unitHas_timeTower' to true for each player that owns it. And store the unit itself in the unit array 'timeTowers'.

I'm getting this error when I run the script, any idea what is the issue here? Thanks.
Screenshot - 5d1bb59b985750f7fd9ed0a90dd04d45 - Gyazo

JASS:
library timeTower requires libMisc, libSetup, unitClassification, bloodTower {

boolean unitHas_timeTower[12];
integer timeTower_time[12];
unit timeTowers[12];


private function OnTimer60() {

  integer i;
  for (0 <= i < 12) {
if (unitHas_timeTower[i] == true) {
   timeTower_time[i] = timeTower_time[i] + 1;
   // + add damage
   }
  }


}


function onGameStart() {
TimerStart(CreateTimer(), 60, true, function OnTimer60);
}

function onCreation() {
unit u = GetTriggerUnit();

if (GetUnitTypeId(u == 't00T')) {
timeTowers[ConvertedPlayer(GetOwningPlayer(u))] = u;
timeTower_time[ConvertedPlayer(GetOwningPlayer(u))] = 0;
unitHas_timeTower[ConvertedPlayer(GetOwningPlayer(u))] = true;
}
}

function onDeath() {
unit d = GetDyingUnit();
if (GetUnitTypeId(d == 't00T')) {
timeTower_time[ConvertedPlayer(GetOwningPlayer(d))] = 0;
unitHas_timeTower[ConvertedPlayer(GetOwningPlayer(d))] = false;
}
}


private function onInit() {
  trigger trg = TriggerCreateOnGameStart();
  trigger creation = CreateTrigger();
  trigger death = CreateTrigger();
  TriggerRegisterAnyUnitEventBJ( creation, EVENT_PLAYER_UNIT_UPGRADE_FINISH );
  TriggerRegisterAnyUnitEventBJ( death, EVENT_PLAYER_UNIT_DEATH );
  TriggerAddAction(trg, function onGameStart);
  TriggerAddAction(creation, function onCreation);
  TriggerAddAction(death, function onDeath);
}

}
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
4,994
When you post a screenshot with the error it lists a line number. Also make sure you highlight that line in the error window before screenshotting so we can see what line it thinks the error is in. You can also use this information yourself to narrow down the issue's location in your script.
  • In OnTimer60 you declared integer i but are using I (capital).
  • In onCreation and onDeath you have misplaced parenthesis: GetUnitTypeId(u == 't00T') should be GetUnitTypeId(u) == 't00T'
  • ConvertedPlayer() takes an integer and returns a player. You want to be using GetConvertedPlayerId() which takes a player and returns an integer. Unless other parts of your code is GUI that uses Player # as an index in arrays then there's no reason to use the converted ones. All they do it shift it up by one so that Player(1) is red rather than Player(0) being red. Use GetPlayerId().
  • What is TriggerCreateOnGameStart() and why are you using it instead of CreateTrigger()?
 
Level 12
Joined
Dec 2, 2016
Messages
733
When you post a screenshot with the error it lists a line number. Also make sure you highlight that line in the error window before screenshotting so we can see what line it thinks the error is in. You can also use this information yourself to narrow down the issue's location in your script.
  • In OnTimer60 you declared integer i but are using I (capital).
  • In onCreation and onDeath you have misplaced parenthesis: GetUnitTypeId(u == 't00T') should be GetUnitTypeId(u) == 't00T'
  • ConvertedPlayer() takes an integer and returns a player. You want to be using GetConvertedPlayerId() which takes a player and returns an integer. Unless other parts of your code is GUI that uses Player # as an index in arrays then there's no reason to use the converted ones. All they do it shift it up by one so that Player(1) is red rather than Player(0) being red. Use GetPlayerId().
  • What is TriggerCreateOnGameStart() and why are you using it instead of CreateTrigger()?

No clue why the 'i's got changed to Capitals. They are all lower case in the code, somehow they converted when posting it here. I updated the code.

And sorry my screenshot program unhighlights the syntax when I select it.

This is highlighted "call TimerStart(CreateTimer(), 60, true, function timeTower__OnTimer60)" from the output error window.


If I change
GetUnitTypeId(u == 't00T') to GetUnitTypeId(u) == 't00T'
I get this error:
Screenshot - 7c46d6141536466ade17ea11b692cd3f - Gyazo

JASS:
unit u = GetTriggerUnit();
if GetUnitTypeId(u) == 't00T' {

}
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
The [i]s were changed because [i] is vB code for italics and the site text input thinks you're trying to do that. It defaults to capital letters. As for the error, I'm now unsure as it seems syntactically correct. What happens if you comment out that if block entirely, or comment out the if and } lines leaving the code in the middle?
 
Level 12
Joined
Dec 2, 2016
Messages
733
The [i]s were changed because [i] is vB code for italics and the site text input thinks you're trying to do that. It defaults to capital letters. As for the error, I'm now unsure as it seems syntactically correct. What happens if you comment out that if block entirely, or comment out the if and } lines leaving the code in the middle?

If I delete the contents of the if statement it still errors. And if I delete the if statement I don't get the same error.


The if statement is removed for the time being. I'm trying to run this

JASS:
function onCreation() {
unit u = GetTriggerUnit();

//if GetUnitTypeId(u) == 't00T' {
timeTowers[GetConvertedPlayerId(GetOwningPlayer(u))] = u;
timeTower_time[GetConvertedPlayerId(GetOwningPlayer(u))] = 0;
unitHas_timeTower[ConvertedPlayerId(GetOwningPlayer(u))] = true;
//}
}

I get the error Screenshot - ccd4484cdd7037c1b19170a073d30a60 - Gyazo
 
Last edited:
Level 12
Joined
Dec 2, 2016
Messages
733
So this is my up to date full script right now. Only error atm is that if statement:
JASS:
if GetUnitTypeId(u == 't00T') {

JASS:
library timeTower requires libMisc, libSetup, unitClassification, bloodTower {

boolean unitHas_timeTower[12];
integer timeTower_time[12];
unit timeTowers[12];

private function OnTimer60() {

  integer i;
  for (0 <= i < 12) {
if (unitHas_timeTower[i] == true) {
   timeTower_time[i] = timeTower_time[i] + 1;
   // + add damage
   }
  }


}


function onGameStart() {
TimerStart(CreateTimer(), 60, true, function OnTimer60);
}




function onCreation() {
unit u = GetTriggerUnit();

if GetUnitTypeId(u == 't00T') {
timeTowers[GetConvertedPlayerId(GetOwningPlayer(u))] = u;
timeTower_time[GetConvertedPlayerId(GetOwningPlayer(u))] = 0;
unitHas_timeTower[GetConvertedPlayerId(GetOwningPlayer(u))] = true;
}
}

function onDeath() {
unit d = GetDyingUnit();
//if GetUnitTypeId(d == 't00T') {
timeTower_time[GetConvertedPlayerId(GetOwningPlayer(d))] = 0;
unitHas_timeTower[GetConvertedPlayerId(GetOwningPlayer(d))] = false;
//}
}


private function onInit() {
  trigger trg = CreateTrigger();
  trigger creation = CreateTrigger();
  trigger death = CreateTrigger();
  TriggerRegisterAnyUnitEventBJ( creation, EVENT_PLAYER_UNIT_UPGRADE_FINISH );
  TriggerRegisterAnyUnitEventBJ( death, EVENT_PLAYER_UNIT_DEATH );
  TriggerAddAction(trg, function onGameStart);
  TriggerAddAction(creation, function onCreation);
  TriggerAddAction(death, function onDeath);
}

}
 
Status
Not open for further replies.
Top