1 decade ago
by drhayes
I've been trying to blog about my RPG-ish project and the useful stuff I'm writing to get it out the door.
Here's the post about what I'm calling
event chains. It's my attempt to stop littering my code with
if (timeElapsed > 32) ...
type code to provide scripted entity behaviors. There's an
associated event chain GitHub repo.
I've also started working on the
Sublime Text 2 ImpactJS plugin. It's available through Package Control (you're using Package Control, right?). I tend to update the plugin when it solves an immediate need of mine; if you think feature X would be useful then please file an issue and I'll see what I can do.
1 decade ago
by mimik
sublime plugin? Thats awesome!
looks like just the thing I need for making scripted events which is awesome!
I used entity chains in my feb 1gam and I am so glad I did. It made scripted events so much easier. Even optimized certain game state checks to not do calculations every update loop. Your code is clear and has tests. Two thumbs up.
1 decade ago
by drhayes
Fantastico! Glad to hear it. Got any suggestions for improvements? I was going to add orUntil
which takes a function and interrupts a wait
.
1 decade ago
by fulvio
@drhayes:
EventChain
sounds brilliant and I might use it in my game :)
I implemented it in the following way for my
player
class just to test it out:
update: function() {
var cx = this.pos.x + 10;
var cy = this.pos.y;
var chain = new EventChain()
.wait(2) // Wait for 10 seconds.
.then(function() { // Then spawn an entity.
ig.game.spawnEntity('EntityCoin', cx, cy);
console.log('Coin spawned at [X: ' + cx + ', Y: ' + cy + ']');
}).repeat(3) // Repeat that 3 times.
.wait(2) // Wait some more.
.then(function() { // Then spawn a different entity.
ig.game.spawnEntity('EntityPotion', cx, cy);
console.log('Potion spawned at [X: ' + cx + ', Y: ' + cy + ']');
}).repeat(); // Repeat the whole thing forever.
this.parent();
}
Unfortunately it doesn't seem to be doing anything. Have I missed something?
1 decade ago
by drhayes
@fulvio: Yup. Try moving that chain instantiation to your
init
method.
init: function() {
// ...
this.chain = EventChain()
.wait(2)
// etc...
},
update: function() {
this.chain();
}
You'll have to move the
cx
and
cy
around, maybe make the chain reference
this
. I was thinking about changing it to take a reference on creation to set the context to run all those functions in so
this
works within them; that would make your case much easier.
1 decade ago
by fulvio
@drhayes Ahh, that makes much more sense. Thanks, working great now!
Drhayes: I do have some ideas. Keep your eyes open for a pull request :)
1 decade ago
by fulvio
@drhayes: EventChain is bloody impressive. I removed countless amounts of code where I was using delays, stages, spawning, etc all over the place. Now I just throw an EventChain into the init()
and trigger it from the update()
and BANG!
Props to you for creating that function. Good work!
1 decade ago
by drhayes
@taddeimania: Great! It'd be my second pull request ever.
1 decade ago
by Neeko
This is almost embarrassing to ask, but how do you include the EventChain in your entity? I understand how to setup the actual chain in the init function, but how do you include the reference to the EventChain function in eventChain.js?
Edit: Solved. From the Impact documentation,
The name of a Module directly corresponds to its file location and name. E.g. the file lib/mygame/my-file.js must define a module with the name 'mygame.my-file', so it can be properly loaded from other Modules.
eventChain.js
defines its module as
ig.module(
'game.system.eventChain'
)
so I added
eventChain.js
to my
lib/game/system
directory, and in
main.js
, I added
.requires(
// Requiring other modules...
'game.system.eventChain'
)
Being global, I can then call
EventChain
from my player entity, as documented
this.chain = EventChain(this) //etc...
1 decade ago
by fulvio
The way I use
EventChain
is like the following:
.requires(
// Requiring other modules...
'game.system.eventChain'
)
Then inside your
Entity
:
text: "foo",
moreText: "bar",
activateEventChain: false,
chain: null,
init: function(x, y, settings) {
...
var self = this;
this.chain = new EventChain()
.wait(0.5).then(function() {
console.log(self.text);
}).wait(0.5).then(function() {
console.log(self.moreText);
}).repeat();
},
update: function() {
if (this.activateEventChain) {
this.chain();
}
this.parent();
}
You should see a "foo" and then "bar" repeat in the console.
1 decade ago
by drhayes
I'll update the documentation to include an "Install" section to clear it up, too.
1 decade ago
by drhayes
I added a new method called waitForAnimation
so you can pause your chain while an animation completes.
You can give it a particular animation or you can just check the current one.
Let me know if it's useful or if you have any questions.
1 decade ago
by Neeko
Very nice drhayes, thank you! I actually came across this scenario the other day and used a
wait()
in the middle of the chain to wait for the animation to play, like so
this.deathEventChain = EventChain(this)
.then(function() {
this.deathFx.play();
this.currentAnim = this.anims.dead.rewind();
})
.wait(1)
.then(this.kill)
.repeat();
Of course, hard coding the number of seconds to wait for each type of animation isn't an elegant solution at all. Thanks again for adding
waitForAnimation
!
1 decade ago
by Joncom
Installed the Sublime Text 2 plugin and restarted the app. Don't seem to see any differences, such as auto-completion for entity.health
or really anything that wasn't already showing up before the install. Anybody got the Sublime Text 2 plugin working?
1 decade ago
by drhayes
You shouldn't have to restart. Are you using Package Control to install?
The plugin doesn't immediately change the syntax to ImpactJS for any JS files. I couldn't come up with a way to detect whether or not you're editing an Impact game reliably from the path alone so you have to do it manually.
If you launch the command window (SHIFT+COMMAND+P on a Mac) and type "impactjs" the only choice should be "Set Syntax: ImpactJS". See if that helps.
Incidentally, a
recent pull request added the ability to mixin your own EventChain methods.
@drhayes I just set up Event Chain and it works great.
Another way it can be used is as a mood manager. Imagine a zombie that gets hungry and seeks food for a while, then sleeps... or a normal character that wanders and then changes into a werewolf... then back to normal, etc.
I'll be watching to see if you add any further developments like the mixin.
1 decade ago
by drhayes
Thanks! I never would have thought of the mixin myself; that came from a contributor.
You should check out my state machine plugin:
https://github.com/drhayes/impactjs-statemachine
I'm using it for AI in the RPGish thing I'm working on to track aggro, etc... event chains definitely help with the transitions. ( =
Page 1 of 1
« first
« previous
next ›
last »