Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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

Code:
class Interpreter

  def gold=(value)

    $game_party.gold += value 

  end

 

  def gold

    return $game_party.gold

  end

 

  def g(value)

    $game_party.gold += value 

  end

 

  def vg

    return $game_party.gold

  end

 

  def actor(id)

    return $game_actors[id]

  end

  def a(id)

    return $game_actors[id]

  end

  

  def actors

    return $game_actors.party.actors

  end

  def as(id)

    return $game_actors.party.actors

  end

  

  def steps

    return $game_actors.party.steps

  end

  def st

    return $game_actors.party.steps

  end

    

  def cure_all

    for actor in $game_party.actors

      actor.recover_all

    end

  end

 

  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  

 

  def variable(id)

    return $game_variables[id]

  end  

  def v(id)

    return $game_variables[id]

  end  

 

  def switch(id)

    return $game_switches[id]

  end  

 

  def sw(id)

    return $game_switches[id]

  end

  

  def get_number(variable, digits=2)

    @parameters[0] = variable

    @parameters[1] = digits

    command_103

  end

 

  def gnum(variable, digits=2)

    @parameters[0] = variable

    @parameters[1] = digits

    command_103

  end

 

  def wait(frames)

    @wait_count = frames * 2

    command_106

  end

  

  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

end

 

class Game_Party

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor  :actors                   # actors

  attr_accessor  :gold                     # amount of gold

  attr_reader   :steps                    # number of steps

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    # Create actor array

    @actors = []

    # Initialize amount of gold and steps

    @gold = 0

    @steps = 0

    # Create amount in possession hash for items, weapons, and armor

    @items = {}

    @weapons = {}

    @armors = {}

  end

end
 
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:
Code:
def execute_call_script(string) # or whatever the default method might be

  if string.include?("call") # shortcut referer; needs to be at the beginning of the line

    string.split!(" ")

    # your code, described in the following

  else

    # default method contents go here

  end

end

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:
Code:
code = splitted_text[1] + splitted_text[2] + "(" + splitted_text[3] + ")"

exec(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":iuj3qhkh said:
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.
 
Neo-Bahamut":tt887to9 said:
@ 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":3ej32at5 said:
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.

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 ^^
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top