Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Question: Dynamic code execution

Reply
Thread Tools

Question: Dynamic code execution

 
 
Thorsten Hater
Guest
Posts: n/a
 
      03-29-2010
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

 
Reply With Quote
 
 
 
 
Aldric Giacomoni
Guest
Posts: n/a
 
      03-29-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.


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/.

 
Reply With Quote
 
 
 
 
Thorsten Hater
Guest
Posts: n/a
 
      03-29-2010
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.
>



 
Reply With Quote
 
Aldric Giacomoni
Guest
Posts: n/a
 
      03-29-2010
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/.

 
Reply With Quote
 
Matthew K. Williams
Guest
Posts: n/a
 
      03-29-2010

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack sndive@gmail.com Python 9 11-14-2007 10:31 PM
Dynamic function execution Andy Wu Python 5 11-26-2006 11:37 AM
Dynamic tracing of C code execution Nikhil C Programming 5 05-16-2006 06:21 AM
"Open-end" Java-session / dynamic compilation and execution Jesper Sahner Java 1 02-01-2005 04:52 AM
Dynamic Execution of Function/Proc Kishor ASP .Net 9 09-27-2003 05:53 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57