Squirrel

The programming language
Welcome to Squirrel Sign in | Join | Help
in Search

Please I need a piece of advise.

Last post 08-28-2008, 1:37 PM by curvedinfinity. 1 replies.
Sort Posts: Previous Next
  •  07-30-2008, 5:07 AM 2662

    Please I need a piece of advise.

    Hi all,

    I´m really new to squirrel and sqplus. What I need is someone confirming that what I want to do is a good way to it. This is it:

    1) My game has a spell system that have different effects on the player.
    2) I will have to expose player class to squirrel
    3) I want to have a directory with different spells (a file per spell) that will be loaded and registered at run time.
    4) To do the register easily I will have something like this in every file:

              SpellTable['this spell name] <- function (Player,...)

        This way I will have all spells in a global table.
        A spell as you can see will be just a function with input the player and
        no ouput. The function just does things like Player->Heal(num of points) etc... play sounds, etc...

    5) I will have a funcion , called "cast" that will be called from C++ (it lives in squirrel side). Something like Cast("name of spell", Player). That will get the correct spell function from the global spell array and call it.

    What do you think about it? Is there any other better/easy way to accomplish what I seek (less binding code, etc...?)

    Thanks in advance,
    HexDump.
  •  08-28-2008, 1:37 PM 2728 in reply to 2662

    Re: Please I need a piece of advise.

    Heya,
    If you want to keep your C++ cleaner, why don't you let Squirrel delegate the callbacks? ... In other words, have your C++ call a delegation squirrel function, passing a bunch of generic info. Then the delegation function in squirrel can call the appropriate spell function...

    function fireball(player,...) {...}
    spellTable["fireball"] <- fireball;

    function doSpell(spellName, player,...) {
    spellTable[spellName](player,...);
    }
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems