Actor の属性みたいなものを初期状態で設定する

「初期状態」というのを表現するのに以下の選択肢がある。

  1. GAME START Panel で trigger する Action CARD を作る
  2. onInit を持つ CARD を作る

初期状態の設定

CARD の設定として簡単に付けられるように props を利用しておくと便利。
以下では onInit を使っているが、 1 の GAME START panel で使う場合には onInitonAction に変えるだけである。

export const PROPS = [
  propActor('target', '')
];

export function onInit() {
  mem.target= props.target

  setVar('target', target);
}

export function onResetGame() {
  delete mem.target;
}

memsetVar

http://gamebuilder.area120.com/setVar.html

Sets a custom variable on the current actor. This is just a key/value pair that gets attached to the actor and can be read by other actors with getVar. All variables get deleted on game reset.

http://gamebuilder.area120.com/mem.html

Memory object for the current actor. This is an object behaviors can freely use to store their state. The contents of this object will depend on what the actor's behaviors have stored it in.

You can use this to store anything that the actor needs to remember from one tick to the next, such as the state it is in, any counters, etc.

Remember to reset any data to its default state on onResetGame.

Note: an actor's memory is private to the actor, so other actors can't access it. If you want to publish a value that other actors can read, you can set it with setAttrib.

card もあるが、 card は CARD 内でしか読めないので、 Actor に対する属性として利用するのは難しい。
mem の最後の説明にあるが、「値を他の Actor からも読めるようにするなら setVar を使う」ということになる。

log(JSON.stringify(mem)); で見てみるとわかるが、 setVar で設定した値は mem の中に __variables として格納されている。

onInit

http://gamebuilder.area120.com/onInit.html

If you implement this function, it will get called when the game is reset, and also when the card has just been added to an actor. You can use this function to initialize your card memory variables.