Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by paulh

Having some problems now my code base has gotten bigger an my noob errors are starting to take roost.


I think i need some sort of event manager/controller because all my classes/entiites just flow on from each other, which is getting quite spaghetti, like.


i guess i want something like this:


init : function(){

this.setupgame();

 // when finished do this:

this.seuplevel();

//when finished do this:

this.get_playerstats();

this.set_up_gameplay();

this_spawn_waves();

//when x has finished :

this.calculate_results();

this.display.results();

this.create_next_level


2. What is and how do you do a callback in impact (not for loading)?

3. how when i call a class do i just pass back the data i want into the location that requested it (callback?)?

What/where should i searching for to find something:

event manager/event dispatcher/game engine controller?

1 decade ago by Datamosh

Maybe you can split your code on files and call the functions

More info:
http://impactjs.com/forums/help/moving-some-auto-generated-code-out-of-my-main-js/page/1#post8806

In Javascript, callbacks are super simple:
function myfunction(callback) {
    if(typeof callback == 'function') callback.call(this, data)
}

myfunction(function() {
    alert('Callback!')
})

I hope it helps!

1 decade ago by paulh


function myfunction(callback) {
    if(typeof callback == 'function') callback.call(this, data)
}

myfunction(function() {
    alert('Callback!')
})


Yea it helps but the above just confuses me :-( m sure its simple once i can understand it...

1 decade ago by quidmonkey

A callback is a function passed as a parameter to another function. Typically, when a set of criteria is met, you make a call back to the passed-in function.

The .call() function Datanosh mentions is a method of all functions that allows you call a function with a specified scope & parameter set.

Regarding clean code I'd recommend doing some googling on Game State and Game State Managers.

1 decade ago by paulh

I'll start googling, although


A callback is a function passed as a parameter to another function. Typically, when a set of criteria is met, you make a call back to the passed-in function. 


makes my head spin!
Page 1 of 1
« first « previous next › last »