Creating a command script language

I have working in it 1hour, but the idea maybe isnt that bad. Im trying to create some sort of scripting 'language' for the call script command that maks the things more easy and quick. For that i plan to use:

-Use of sortcuts to the game information
-Use of event commands with scripts
-Create new functions for this system

Im posting this for feedback from scripters.,ideas,wrong,bad,utopia,etc. Anyway is fun.

We can make everything, and its very quick to do. Here a example:

def cure_all
for actor in $game_party.actors
actor.recover_all
end
end

This is the easy way of doing it.

def cure(id=0)
if id == 0
for actor in $game_party.actors
actor.recover_all
end
else
$game_actors[id].recover_all
end
end

I think that knowing that all database ids start with 1, will be nice to treat a 0 like a "for all". And maybe make this the default values.

Also i think that will be nice to make that each method have a shorter one:
cure- c o cu
cure_all -cu_a

def gold=(value)
$game_party.gold += value
end

def gold
return $game_party.gold
end

Maybe when setting variables values we can make that a value of 0 sets it to 0. If not, to reduce the gold to 0 you have to call gold=-99999.
Another idea is if the use of = in method names is correct or not. Its more slow,that for sure.

A example call script.

gold=500 # This add 500 gold
(a 1).name = 'Wilfred' # (a 1) is like $game_actors[1]
for a in actors # actors is an alias of $game_party.actors
a.hp+=20
end
get_number(1) # This is like a input number command.

In the same way that cure and cure all:


def hp_mod(hp, id=0)
if id == 0
for actor in $game_party.actors
actor+=hp
end
else
$game_actors[id]+=hp
end

end
That can be aliased like mhp or hp. The problem here may be if you want
to make that trully all actors get the bonus. Maybe make that with a id=-1?
Also a nice idea for ids arguments will be to be arrays...

  1. class Interpreter
  2.   def gold=(value)
  3.     $game_party.gold += value
  4.   end
  5.  
  6.   def gold
  7.     return $game_party.gold
  8.   end
  9.  
  10.   def g(value)
  11.     $game_party.gold += value
  12.   end
  13.  
  14.   def vg
  15.     return $game_party.gold
  16.   end
  17.  
  18.   def actor(id)
  19.     return $game_actors[id]
  20.   end
  21.   def a(id)
  22.     return $game_actors[id]
  23.   end
  24.  
  25.   def actors
  26.     return $game_actors.party.actors
  27.   end
  28.   def as(id)
  29.     return $game_actors.party.actors
  30.   end
  31.  
  32.   def steps
  33.     return $game_actors.party.steps
  34.   end
  35.   def st
  36.     return $game_actors.party.steps
  37.   end
  38.    
  39.   def cure_all
  40.     for actor in $game_party.actors
  41.       actor.recover_all
  42.     end
  43.   end
  44.  
  45.   def cure(id=0)
  46.     if id == 0
  47.       for actor in $game_party.actors
  48.         actor.recover_all
  49.       end
  50.     else
  51.       $game_actors[id].recover_all
  52.     end
  53.   end  
  54.  
  55.   def variable(id)
  56.     return $game_variables[id]
  57.   end  
  58.   def v(id)
  59.     return $game_variables[id]
  60.   end  
  61.  
  62.   def switch(id)
  63.     return $game_switches[id]
  64.   end  
  65.  
  66.   def sw(id)
  67.     return $game_switches[id]
  68.   end
  69.  
  70.   def get_number(variable, digits=2)
  71.     @parameters[0] = variable
  72.     @parameters[1] = digits
  73.     command_103
  74.   end
  75.  
  76.   def gnum(variable, digits=2)
  77.     @parameters[0] = variable
  78.     @parameters[1] = digits
  79.     command_103
  80.   end
  81.  
  82.   def wait(frames)
  83.     @wait_count = frames * 2
  84.     command_106
  85.   end
  86.  
  87.   def hp_mod(hp, id=0)
  88.     if id == 0
  89.       for actor in $game_party.actors
  90.         actor+=hp
  91.       end
  92.     else
  93.       $game_actors[id]+=hp
  94.     end
  95.  
  96.   end
  97. end
  98.  
  99. class Game_Party
  100.   #--------------------------------------------------------------------------
  101.   # * Public Instance Variables
  102.   #--------------------------------------------------------------------------
  103.   attr_accessor  :actors                   # actors
  104.   attr_accessor  :gold                     # amount of gold
  105.   attr_reader   :steps                    # number of steps
  106.   #--------------------------------------------------------------------------
  107.   # * Object Initialization
  108.   #--------------------------------------------------------------------------
  109.   def initialize
  110.     # Create actor array
  111.     @actors = []
  112.     # Initialize amount of gold and steps
  113.     @gold = 0
  114.     @steps = 0
  115.     # Create amount in possession hash for items, weapons, and armor
  116.     @items = {}
  117.     @weapons = {}
  118.     @armors = {}
  119.   end
  120. end
Expand to see the code.
And what's your problem now or why did you post this in script support?
gerrtunk wrote:
Im posting this for feedback from scripters.,ideas,wrong,bad,utopia,etc.
In general, it's not the worst concept. Your approach is interesting, however far from being too useable in my opinion - reason being that you'd have to manually modify it for everything non-default... and you don't need Call Script for default. You're also adding a lot of methods and variables that could be left out more easily.

Instead, I think what you want to do here is try to grab the Call Script string (if it is one... but it should be really) and seperate it. First of all, you want to do this:
  1. def execute_call_script(string) # or whatever the default method might be
  2.   if string.include?("call") # shortcut referer; needs to be at the beginning of the line
  3.     string.split!(" ")
  4.     # your code, described in the following
  5.   else
  6.     # default method contents go here
  7.   end
  8. end
Expand to see the code.


So, that'd be an example for a main construct for this. You can see it's only a modified method as of yet, that perfectly retains it's default functionality (though I chose the easy way out and did 'include?', while you really would have to check for the beginning of the line... too tired to look anything up now though ~.~).

For communication purposes, let's assume this Call Script string:
call gold += 500

Now what you put in the execution block is an executing handler: Analyze the string you have, maybe use has_method? to auto-check for methods within classes (though that might be buggy...), otherwise use class referers (such as game_party.gold) to be sure, and also check for the operator. Then, pack all the other things in the line (in this case only '500') as arguments for that method, and wrap it all in a neat string block, such as:
  1. code = splitted_text[1] + splitted_text[2] + "(" + splitted_text[3] + ")"
  2. exec(code)
Expand to see the code.


That way would be perfectly compatible with all scripts around the world, however not quite as short-ey... either way, consider that people might want to read it later... Personally, I hate it when people try to be cool by adding something to events by Call Script. When I actually have to look for it, and then see it has a weird name in it like "c g 500", I wouldn't be too glad... so, having the spelled out terms in there wouldn't help imo.

Note that everything above this oint was written while being half asleep and therefore maybe makes no sense at all >>




Aside from that, you really really want to avoid stuff like this:
gerrtunk wrote:
gold=500 # This add 500 gold

The line tells me and 99% of all the other scripters that you se the party gold to 500, not add it. You mustn't mess with known conventions or operators if you want this to be any useable at all.
Mmm.
-Its true that g 500 its hard to read: but its also trully faster. That was the reason to make it optional.
We are talking about event programing. I dont see the reason why its bad this, why anybody would check it ? and i have to waste my time for they?
We are not talking in creating something like a script that is coded with shortcuts...

Also one idea to make it usable is speed. Using shortcuts like that you can make a lot of commands in a few seconds.

-Ok, i will use gold 500, and vgold for varibles values.

-I dont understand what are you trying to do. ¿Why its incompatible?
A scripter that that uses other scripts obviously will need to create his fuctions, always,no? Or just use normal call scripts because are compatible.

All the default things arent modified by new scripts(at command level, of course).
@ Brewmeister: Oops :shock:
Seems like I was too tired yesterday to read correctly :)


Ok, I think the same way BlueScope (in some parts).
I think the methods are not a good idea.
I agree that the usual event commands do not offer everything you might need but still, that's not because of methods like "g += 10".
I mean, I don't care if I have to write $game_party.gold or just g at a few places.

You probably should check out this:
http://hesperides.xooit.com/f42-World-Dreamer.htm (problem might be, that it's french :)
Their project looks much more promising since it adds really useful methods like "save(filename)" which creates a quicksave.
BlueScope wrote:
  1. code = splitted_text[1] + splitted_text[2] + "(" + splitted_text[3] + ")"
  2. exec(code)
Expand to see the code.



Be careful Blue, you wouldn't want to use the Kernel#exec without being very specific about what you want.
Neo-Bahamut wrote:
@ Brewmeister: Oops :shock:
Seems like I was too tired yesterday to read correctly :)


Ok, I think the same way BlueScope (in some parts).
I think the methods are not a good idea.
I agree that the usual event commands do not offer everything you might need but still, that's not because of methods like "g += 10".
I mean, I don't care if I have to write $game_party.gold or just g at a few places.

You probably should check out this:
http://hesperides.xooit.com/f42-World-Dreamer.htm (problem might be, that it's french :)
Their project looks much more promising since it adds really useful methods like "save(filename)" which creates a quicksave.


I have a save script in final testing that let manage all the aspects of the save system with call scripts. I wanted to add this, of course, anyway that project looks good(i didnt know that one already exist). I will register in that forum and tell they my ideas.
gerrtunk wrote:
Mmm.
Its true that g 500 its hard to read: but its also trully faster. That was the reason to make it optional.
We are talking about event programing. I dont see the reason why its bad this, why anybody would check it ? and i have to waste my time for they?
We are not talking in creating something like a script that is coded with shortcuts...

Also one idea to make it usable is speed. Using shortcuts like that you can make a lot of commands in a few seconds.

Your argumentation is flawed in big circles... no matter what you do, you want it to be readable later on, by as many people as possible. If you say event folks don't need that, then you're right, because for the overviewable amount of event commands, you can assume most people knowing what stuff means in general. Scripting, however (and you are talking about scripting) requires readable code, as most community-released stuff is far from being common knowledge. Now of course it's possible to create shorter and faster commands than ever.. how about "2", which adds 1 gold unit to the party's amount. Noone can read it, but who cares, right?
Seriously, if you think some areas require readability and others are fine with single characters, then you should go back to the school bench and check the chapter about documentation and scripting style... or make scripts for your own preferences, but not for the community.

Quote:
I dont understand what are you trying to do. ¿Why its incompatible?
A scripter that that uses other scripts obviously will need to create his fuctions, always,no? Or just use normal call scripts because are compatible.
You don't get my point... if you use a structure like mine, the user can throw it in the project and happily use all of his custom methods without doing anything else such as defining new methods within Interpreter.


@Zeriab: As this is script support, I tried to outline a solution, not provide a completely functional approach. But you're right, it definately should be mentioned ^^

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=72548