ID:167365
 
Ok i have seen this in a few games now and it killing me not knowing how to do it..
the first game i have seen it in was console, were you could write progames to hack somone else's computer or what ever. I have also seen it in some robot games were you write scripts for you robot to run..

im making a comand line type game that i need to be able to have a programing lang in the game.. i know how to make command line commands but i would like to be able to write scripts that do what ever..

im not sure how to go about make a programing lang in DM

any help or input wold be great.. TY
I've been wanting to make a programming game as well where you program a robot. It's just reading text and making it do something according to that text.
If you wanted to make a code with procs(like in byond) for your robot, you'd have to find the (). Anything before on the same line or between brackets, or whatever would probably be the name. Any spaces beforehand are omitted if you use tabs for branching.
That's my best guess :\
Isn't that called parsing?

Oh yeah, above is a complex way but it's free form. Another way is just having the player choose what to put in the code, but you know exactly what is being inputted. The former is finding needles in haystacks and the latter says specifically "I'm making a proc", or "create this variable", probably using the statpanel or a cool GUI.
In response to SJRDOZER
yeah i was talking to one of the ppl that has a programing lang in has game and he said summthing about praesing or whatever..
In response to Jex
no one know anythings esl about this??
Jex wrote:
im not sure how to go about make a programing lang in DM

You just need to parse the text into commands and have functions that go through it one piece at a time.

The following is a hasty and not nearly complete example that just shows how you might start to throw something together.
#define GREATER 0
#define LESS 1
#define EQUALS 2
#define NOT_EQUAL 3

var/list/statements = list("if" = /statement/if, "while" = /statement/while, etc.)

code_block
var/list/lines[0]
proc/execute()
for(var/statement/statement in lines)
statement.evaluate()

statement
var/code_block/block
proc/evaluate()
if
var
left, right, operator
evaluate()
var/evaluation
switch(operator)
if(GREATER) evaluation = (left>right)
if(LESS) evaluation = (left<right)
if(EQUALS) evaluation = (left==right)
if(NOT_EQUAL) evaluation = (left!=right)
if(true) block.execute()
return true
while
evaluate()
while(..(left, right, operator)){}
//and so on

proc/generate_code(code)
var
indentation = 0
list
code_tree[0]
command[0]
index = 1
next_index = 0, N = 0
while(index)
next_index = findtext(code, "/", index)
N = findtext(code, ascii2text(13), index)
if(N < next_index) next_index = N
command = parse_command(copytext(code, index, next_index))
if(!command) return 0
//continue on from there, I'm not going to make up a full example

proc/parse_command(command)
//this breaks a command down into its parts
var
list/L = new
index = 0, N = 0
T = ""
index = findtext(command, "(")
N = findtext(command, " ")
if(N < index) index = N
T = copytext(command, 1, index)
if(!(T in statements)) return 0
//continue parsing
//get either an evaluation or a string of arguments depending on whether the command has parenthesis or not

You could set up objects that do things based on what type of code they represent, similar to the above. Also, it would probably be easier to do it based on braces and semicolons than it would on indentation, as is done in other languages.

Either way, you just set up a way to issue commands, and a way to represent it with text, then a way to convert the text into a set of the commands.

Anyway, that's just something to kick-start the gears.