- Joined
- Jan 13, 2019
- Messages
- 284
For build my map, im using warcraft 1.31 with TS along this template cipherxof/wc3-ts-template
But im getting problem when assign values to globals variables, when i initialize them can get the value when printing them, but when i imported them to anothers .ts script they have nil value, why this happend?, what im doing wrong?
This is how i set my map:
main.ts
init_map.ts
init_players.ts
init_game.ts
In this case init_game dont execute completely, because timer_start is nil.
Until now only players variables are accesible, but rects, timers, or units dont work outside the init_map.ts script.
But im getting problem when assign values to globals variables, when i initialize them can get the value when printing them, but when i imported them to anothers .ts script they have nil value, why this happend?, what im doing wrong?
This is how i set my map:
main.ts
JavaScript:
import { addScriptHook, W3TS_HOOK } from "w3ts/hooks";
import { File } from "w3ts/system/file"
import { Timer } from "w3ts/handles/timer";
import { init_map } from "init_map";
import { init_players } from "init_players";
import { init_game } from "init_game";
function Main() {
const gameStart = new Timer();
gameStart.start(1.0, false, ()=>{
try {
init_map();
init_players();
init_game();
}
catch (e) {
File.write("error.txt", e);
}
})
}
addScriptHook(W3TS_HOOK.MAIN_AFTER, Main);
init_map.ts
JavaScript:
import { Hero } from "hero";
import { Players } from "w3ts/globals/index";
import { MapPlayer, Rectangle, Timer, Unit } from "w3ts/handles";
export const playing:MapPlayer[] = [];
export const team1:MapPlayer[] = [];
export const team2:MapPlayer[] = [];
export let team1_leader:MapPlayer;
export let team2_leader:MapPlayer;
export let timer_start:Timer;
export let timer_spawn:Timer;
export let tower1_1: Unit;
export let tower1_2: Unit;
export let tower1_3: Unit;
export let tower1_4: Unit;
export let tower1_5: Unit;
export let barrack1: Unit;
export let core1: Unit;
export let tower2_1: Unit;
export let tower2_2: Unit;
export let tower2_3: Unit;
export let tower2_4: Unit;
export let tower2_5: Unit;
export let barrack2: Unit;
export let core2: Unit;
export let start:Rectangle;
export let base_left:Rectangle;
export let base_right:Rectangle;
export let spawn_left:Rectangle;
export let spawn_right:Rectangle;
export let core_backdoor = {left:0, right:0}
export let player_done = {amount:0};
export const selector = FourCC("h00F");
export const meleeUnit = FourCC("h005");
export const rangedUnit = FourCC("h006");
export const heroes:Hero[] = []
export function init_map(){
team1_leader = Players[10];
team2_leader = Players[11];
team1.push(team1_leader);
team2.push(team2_leader);
timer_spawn = new Timer();
timer_start = new Timer();
tower1_1 = Unit.fromHandle(gg_unit_h001_0012);
tower1_2 = Unit.fromHandle(gg_unit_h002_0035);
tower1_3 = Unit.fromHandle(gg_unit_h003_0029);
tower1_4 = Unit.fromHandle(gg_unit_h008_0046);
tower1_5 = Unit.fromHandle(gg_unit_h008_0026);
barrack1 = Unit.fromHandle(gg_unit_h004_0028);
core1 = Unit.fromHandle(gg_unit_h000_0014);
tower2_1 = Unit.fromHandle(gg_unit_h001_0097);
tower2_2 = Unit.fromHandle(gg_unit_h002_0111);
tower2_3 = Unit.fromHandle(gg_unit_h003_0086);
tower2_4 = Unit.fromHandle(gg_unit_h008_0093);
tower2_5 = Unit.fromHandle(gg_unit_h008_0094);
barrack2 = Unit.fromHandle(gg_unit_h004_0067);
core2 = Unit.fromHandle(gg_unit_h000_0075);
tower1_2.invulnerable = true;
tower1_3.invulnerable = true;
tower1_4.invulnerable = true;
tower1_5.invulnerable = true;
barrack1.invulnerable = true;
core1.invulnerable = true;
tower2_2.invulnerable = true;
tower2_3.invulnerable = true;
tower2_4.invulnerable = true;
tower2_5.invulnerable = true;
barrack2.invulnerable = true;
core2.invulnerable = true;
base_left = Rectangle.fromHandle(gg_rct_BASE_LEFT);
base_right = Rectangle.fromHandle(gg_rct_BASE_RIGHT);
spawn_left = Rectangle.fromHandle(gg_rct_SPAWN_LEFT);
spawn_left = Rectangle.fromHandle(gg_rct_SPAWN_RIGHT);
}
init_players.ts
JavaScript:
import { playing, team1, team2 } from "init_map";
import { Players } from "w3ts/globals/index";
export function init_players(){
for (const p of Players) {
if (p.controller === MAP_CONTROL_USER && p.slotState === PLAYER_SLOT_STATE_PLAYING) {
playing.push(p);
p.id < 5 ? team1.push(p) : team2.push(p);
}
}
}
init_game.ts
JavaScript:
import { playing, selector, start, timer_spawn, timer_start } from "init_map";
import { Rectangle, TimerDialog, Trigger, Unit } from "w3ts/handles/index";
export function init_game(){
const trig = new Trigger();
const td = new TimerDialog(timer_start);
const start = Rectangle.fromHandle(gg_rct_START)
trig.registerTimerEvent(1.00, false);
trig.addAction(()=>{
for (const p of playing) {
let wisp = new Unit(p, selector, start.centerX, start.centerY, 90);
}
td.display = true;
td.setTitle("Start in...");
timer_start.start(20.0, false, ()=>{
td.destroy();
timer_spawn.start(10.0, true, null);
});
});
}
In this case init_game dont execute completely, because timer_start is nil.
Until now only players variables are accesible, but rects, timers, or units dont work outside the init_map.ts script.