Question: Dynamic code execution

Discussion in 'Ruby' started by Thorsten Hater, Mar 29, 2010.

  1. Hi

    I'm currently writing a small game application in ruby.
    The problem is, not all of the rules are static, meaning some
    of the actions in the game are allowed to change them.
    My question is, what is the best and safest way to implement this
    feature?
    Specifically, I have database of items, which may change parts of
    the rules upon activation.
    Storing code along with those and eval()ing it at runtime feels
    kind of awkward and not really safe, but seems the most flexible
    way at a first glance.
    Has anybody ideas and/or pointers to this matter?

    Thorsten
     
    Thorsten Hater, Mar 29, 2010
    #1
    1. Advertising

  2. Thorsten Hater wrote:
    > Hi
    >
    > I'm currently writing a small game application in ruby.
    > The problem is, not all of the rules are static, meaning some
    > of the actions in the game are allowed to change them.
    > My question is, what is the best and safest way to implement this
    > feature?
    > Specifically, I have database of items, which may change parts of
    > the rules upon activation.


    Alright.. So store the rules in one or more hashes depending on what
    they are and how they can change, and refer to whatever key you need to
    read the rule (or setting) in the hash.
    That's one way.
    --
    Posted via http://www.ruby-forum.com/.
     
    Aldric Giacomoni, Mar 29, 2010
    #2
    1. Advertising

  3. My problem is, how to formulate the rules in ruby?
    Let me give an example:
    Lets say in an RPG context, the max skill level is 10,
    but if the player chooses to be an elf, he gets 11 as a
    max skill level in bow shooting. Additionally there
    exists something like a special feature which increases
    the max skill level by another point.
    At the moment I'm thinking about a mini DSL based on
    method_missing, but I'm looking for alternatives.

    Aldric Giacomoni wrote:
    > Thorsten Hater wrote:
    >
    >> Hi
    >>
    >> I'm currently writing a small game application in ruby.
    >> The problem is, not all of the rules are static, meaning some
    >> of the actions in the game are allowed to change them.
    >> My question is, what is the best and safest way to implement this
    >> feature?
    >> Specifically, I have database of items, which may change parts of
    >> the rules upon activation.
    >>

    >
    > Alright.. So store the rules in one or more hashes depending on what
    > they are and how they can change, and refer to whatever key you need to
    > read the rule (or setting) in the hash.
    > That's one way.
    >
     
    Thorsten Hater, Mar 29, 2010
    #3
  4. Thorsten Hater wrote:
    > My problem is, how to formulate the rules in ruby?
    > Let me give an example:
    > Lets say in an RPG context, the max skill level is 10,
    > but if the player chooses to be an elf, he gets 11 as a
    > max skill level in bow shooting. Additionally there
    > exists something like a special feature which increases
    > the max skill level by another point.
    > At the moment I'm thinking about a mini DSL based on
    > method_missing, but I'm looking for alternatives.


    Things which will be crucial to you here are going to be extending
    modules and classes, as well as inheritance.

    class Race
    MAX_SKILL_LEVEL = 10
    end

    class Elf < Race
    MAX_SKILL_LEVEL += 1
    end

    Race::MAX # => 10
    Elf::MAX # => 11

    And you can also specify unique skill levels (for instance, your
    Swordmanship max skill may be 22 because of a unique sword you have, it
    doesn't raise EVERY skill max...)

    Does that help a little?
    --
    Posted via http://www.ruby-forum.com/.
     
    Aldric Giacomoni, Mar 29, 2010
    #4
  5. On Mon, 29 Mar 2010, Thorsten Hater wrote:

    > Hi
    >
    > I'm currently writing a small game application in ruby.
    > The problem is, not all of the rules are static, meaning some
    > of the actions in the game are allowed to change them.
    > My question is, what is the best and safest way to implement this
    > feature?
    > Specifically, I have database of items, which may change parts of
    > the rules upon activation.
    > Storing code along with those and eval()ing it at runtime feels
    > kind of awkward and not really safe, but seems the most flexible
    > way at a first glance.
    > Has anybody ideas and/or pointers to this matter?
    >
    > Thorsten
    >
    >


    You might consider looking at this, which talks about some dynamic game
    generation I've done (and if you have further questions, I've got more):

    http://aetherical.com/2008/4/25/classes-on-the-fly
     
    Matthew K. Williams, Mar 29, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kishor

    Dynamic Execution of Function/Proc

    Kishor, Sep 24, 2003, in forum: ASP .Net
    Replies:
    9
    Views:
    556
    Kishor
    Sep 27, 2003
  2. Jesper Sahner
    Replies:
    1
    Views:
    368
    Rhino
    Feb 1, 2005
  3. Andy Wu

    Dynamic function execution

    Andy Wu, Nov 25, 2006, in forum: Python
    Replies:
    5
    Views:
    308
    Fredrik Lundh
    Nov 26, 2006
  4. Nikhil

    Dynamic tracing of C code execution

    Nikhil, May 12, 2006, in forum: C Programming
    Replies:
    5
    Views:
    1,635
    Frank Pittel
    May 16, 2006
  5. Ggianks
    Replies:
    1
    Views:
    320
    Goran Pusic
    Aug 19, 2010
Loading...

Share This Page