Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

Pacman Tutorial/Access functions in other scripts

A topic by Meganegora created Sep 05, 2016 Views: 579 Replies: 2
Viewing posts 1 to 2

Pretty new to typescript. Trying to figure out how I would access the functions in a player behavior in another script? I have player added to a game namespace like the paceman tutorial:

namespace Game {

export let initMap: initMapBehavior;

export let player: playerBehavior;

export let score: number;

export let won: boolean;

}

I was hoping I would access my player functions from other scripts by doing something like

Player.jump

But I'm getting an identifier expected error.

Well, i haven't read the pacman tutorial but if you have this:

namespace Game {
export let Player : PlayerBehavior;
}

you need to assign the player in your behavior.

class PlayerBehavior extends Sup.Behavior {
awake() {
Game.Player = this; // This could have been done in the start() or anywhere.
}
}

And with that you can access all the public methods or variables in your behavior using (As a side note in typescript all methods and variables are public by default)

Game.Player.jump(); // Or any other method

Thanks! Turns out I had my actors in the wrong order in my scene...Took me a while to figure that out. Didn't realize it mattered!