ID:265247
 
Would there be an example of making ingame coding?

Like on Exadv1's console.

I really need an example, and if anyone could get me one, I'll gladly use it.

--------------------------------

Example:
Harry logs in and makes a program. He types like:

var/hi = 0
if(hi == 1)
usr << "Uh-oh."


After this, he has created his program. It is automaticly made (and can be transferred to floppy or burnt on a CD later).

I need this to be a bit the same as BYOND coding. But how do I do this?

Also, I need to block certain coding, like, e.x.
world << "<font size=1000>SPAM!"


I'd block spam with my own code, and the "world <<" command is never executed.

But anyhow, how do I make it so it actually does stuff?
Let me rephrase your question:

"How do I create an object-oriented programming language using the same structures as BYOND, allow programs made with it through Dream Seeker to be ran on the fly, actually taking the place of the compiled DM code, except for where it's something disruptive or destructive?"

I don't have a solution. I just wanted to make sure you knew what you're asking.
In response to Hedgemistress
Actually, its,

"How do I create an object-oriented programming language like in console (ExCode), allow programs made with it through Dream Seeker to be ran on the fly, except for where it's something disruptive or destructive to the game?"
Well, I belive you could have a simulated effect by using text2file and other such procs to send the code to a file, then execute a command line compile, (Does this exist?) and then open and link connected users to the new world, then close the old one, although I'm not sure how functional or practical this would be. That's if it's even possible.

By command line, I mean such as this:

dreammaker.exe "Utopia Chronicles/Utopia Chronicles.dme" -compile
dreamdaemon.exe "Utopia Chronicles/Utopia Chronicles.dme"

And things of that nature. I'm not familiar with this sort of thing, as I have never needed to do any scripting to this effect.


~Polatrite~
In response to Polatrite
I don't want to connect players to a whole new game!

I just need an example!

Like, I login, and use a computer. I'd make a program, and...
                   *** As in console ***
* > make text.txt *
* > write text.txt *
* > Hi! *
* > [stop] *
* > read text.txt *
* Hi! *
* > make file.exe *
* > write file.exe *
* > del text.txt *
* > echo Hacked! *
* > [stop] *
* > run file.exe *
* text.txt deleted. *
* Hacked! *
*********************


Point is, I don't even know where to start!

Must I use findtext()? If so, how must I use it?

I just need a example of creating a file with the switch() command.

BYOND DM Code:

switch(input("Hello!","") in list("Hi!","Bye!"))
if("Hi!")
usr << "Hi!"
if("Bye!")
usr << "Bye!"

Computer Code:

?

Of course, the output,
world << "Hi!"

Is not allowed.
This can get very, very complicated. I suggest you decide on a simple syntax for your scripts, and work upwards from there. Deadron's TextHandling library would be very helpful in parsing each command.
In response to Crispy
...thus being so complicated that I am in need of a very small example of only 1 command...
In response to Phoenix Man
Phoenix Man wrote:
I don't want to connect players to a whole new game!

Thats a nice thought, obviously you don't want to do that, but I don't see many other options presenting themselves. You can't modify a .dmb file on the fly in that way. You can make psuedo code, by recoding the entire structure yourself using lots of variables, and thats about it.
In response to Phoenix Man
Heh. Okay, okay. I should be going to bed now, but I'll take pity on you and give you a few small hints first. =) I'm doing all this from memory, and it's late, so please forgive any mistakes.

First, let's decide on a simple overall syntax. Commands are separated by lines, extra whitespace (like spaces, tabs, blank lines) is ignored, and each command follows this basic syntax:

command blah thingy etc.

First we need the file. TextHandling's dd_file2list() can help.

var/commands[]=dd_file2list("myfilename","\n")

Now we have a list of every line in the file. Not hard, was it? You can now loop through this list to get each command line by line:

for (var/command in commands)
//Remove leading/trailing whitespace
command=trim(command)

Now that's done, we need to get down to parsing the command. A simple "display message to player" command might look like:

displaymessage src Hey, how ya doin'?

We can use dd_text2list() from the TextHandling library to split this command up into words, or (more colloquially) chunks.

var/commandchunks[]=dd_text2list(command)

The first word will be our command. For this example, I'll only be using one command; "displaymessage"; but you can add extra ones easily. Note the use of lowertext() to make it so the player can use "DispLAYmEsSaGe" if they want and it'll still work.

switch(lowertext(commandchunks[1]))
if ("displaymessage")
//Display a message!

Now, the second word is who we're displaying it to. Note that this should of course be indented under the previous code snippet.

var/targets[0] //List of targets
switch(lowertext(commandchunks[2]))
if ("src") targets+=src
if ("usr") targets+=usr
if ("view") targets+=view(src)
if ("viewusr") targets+=view(usr)

Finally, we have to display the text to our targets. The text we want is the remainder of the line; this is most easily retrieved by looping through the remaining words, adding them to another list, and using dd_list2text on that list.

var/displaywords[0]
for (var/X = 3 to length(commandchunks))
displaywords+=commandchunks[X]

targets << dd_list2text(displaywords, " ")

Tada! A very, very simple scripting system. This system doesn't include flow control (like loops and if statements) or any kind of variables, and it isn't even particularly good, but it's a start. Don't say I didn't try to help you! =)
In response to Crispy
error:trim:undefined proc
Ok.....
In response to Phoenix Man
If I remove the trim command...
...it just hangs. It crashes.

var/commandchunks[]=dd_text2list(command)
When executing this, it hangs.
In response to Crispy
var/commands[]=dd_file2list("myfilename","\n")
for (var/command in commands)
//Remove leading/trailing whitespace
command=trim(command)
var/commandchunks[]=dd_text2list(command)
switch(lowertext(commandchunks[1]))
if ("displaymessage")
var/targets[0] //List of targets
switch(lowertext(commandchunks[2]))
if ("src") targets+=src
if ("usr") targets+=usr
if ("view") targets+=view(src)
if ("viewusr") targets+=view(usr)
var/displaywords[0]
for (var/X = 3 to length(commandchunks))
displaywords+=commandchunks[X]
targets << dd_list2text(displaywords, " ")

proc/trim(var/list/s)
if(!s) return s
var/i
for(i = 1, i <= s.len, ++i)
if(text2ascii(s, i) > 32) break
if(i > 1)
if(i > s.len) return ""
s = copytext(s, i)
for(i = s.len, i > 0, --i)
if(text2ascii(s, i) > 32) break
if(i < s.len)
if(i <= 0) return ""
s = copytext(s, 1, i + 1)
return s


This does not work.
Can anyone make it work?

Runtime Error!

runtime error: Cannot read "displaymessage src Hey, how ya...".len
proc name: trim (/proc/trim)
source file: heh.dm,24
usr: Phoenix Man (/mob)
src: null
call stack:
trim("displaymessage src Hey, how ya...")
Phoenix Man (/mob): test()
In response to Phoenix Man
I've fixed proc/trim.

Now it just keeps crashing.
In response to Phoenix Man
The problem would be preventing potentially disruptive/destructive commands. Outputting a message to the world could be used for spam, but it does have plenty of legitimate uses, so you can't necessarily eliminate a command because it could be potentially bad. Of course, to do anything about this you'd need a moderately functional language first, because if you have no programming language, then of course you can't make any harmful programs. I'd say, worry about making the language itself first.
In response to OneFishDown
I can't worry on the language.
As long as the language can't be processes, I can't, and see no reason, to add any further commands!

All I need is the bug fixed! It just hangs, stops responding!
In response to Phoenix Man
mob/verb/test()
var/commands[]=dd_file2list("myfilename","\n")
for (var/command in commands)
//Remove leading/trailing whitespace
command=trim(command)
var/commandchunks[]=dd_text2list(command)
switch(lowertext(commandchunks[1]))
if ("displaymessage")
var/targets[0] //List of targets
switch(lowertext(commandchunks[2]))
if ("src") targets+=src
if ("usr") targets+=usr
if ("view") targets+=view(src)
if ("viewusr") targets+=view(usr)
var/displaywords[0]
for (var/X = 3 to length(commandchunks))
displaywords+=commandchunks[X]
targets << dd_list2text(displaywords, " ")


proc/trim(s)
if(!s) return s
var/i
var/l = length(s)
for(i = 1, i <= l, ++i)
if(text2ascii(s, i) > 32) break
if(i > 1)
if(i > l) return ""
s = copytext(s, i)
for(i = l, i > 0, --i)
if(text2ascii(s, i) > 32) break
if(i < l)
if(i <= 0) return ""
s = copytext(s, 1, i + 1)
return s


This is the whole code again, changed.

When I click test, and allow access to the file, Dreamseeker hangs and stops responding.
In response to Phoenix Man
You seem to be operating under the delusion here that the code Crispy showed you is a magically complete solution--or even the first step--to your problem. It is not. But you've been going crazy trying to get that code to compile since you saw it. I think you're thinking that if you can get it to work out, just a little tweaking will make it do what you want. It won't.

Crispy's example was basically to show you some of the first steps in thinking out how to begin handling the issue. It's a special case of a special case that gives a brief glimpse into just a couple of the issues you'd have to tackle. In reality the problem you're trying to solve is so complex that even if the language you developed was very much dumbed-down from DM, it'd still take a great deal of work. You need at least a small understanding of compiler theory to do this.

I don't want to be the voice of doom here and tell you this is completely impossible, but "wildly ambitious" wouldn't be so far to jump. Concentrating on this piece of code isn't going to help you. What you need to do is glean from it that the issue is broader than you'd anticipated. It'll take a lot of work to do this, and it may well be (or may not be, for all I know) beyond your present level of skill. You should consider some alternatives.

Lummox JR
In response to Phoenix Man
As long as the language can't be processes, I can't, and see no reason, to add any further commands!

Way to almost make a sentence there.

If I understand you correctly... you just want to get this one single command working as an example, and if that works, you think you'll be able to make a whole language in the same way. Is that right? If so, you're definitely going about this the wrong way.

"Give me an example of one command and I'll then be able to make a whole language!" is a distressingly naive view of coding. Language isn't about words (commands) so much as it is about structure and syntax.

I mean, if what you're going for is where you've got somewhere between three and several dozen pre-defined commands that players can enter into a computer and each command does something pre-defined, that's well within your grasp, but if you're talking about anything more complicated, I really don't think you're going to get there. If you don't understand enough about programming languages to figure out how to do this on your own, then you don't know enough about them to make one, even a little simu-pseudo-language.
In response to Hedgemistress
I wish to have Crispy's code to work.

It works, and it processes. Simple.
However, it crashes.

I just want to know why it crashes.
In response to Lummox JR
YAY!
I got it to work!

My snipplet (for anyone to use)

mob/verb/test()
var/commands[]=dd_file2list("myfilename","\n")
for (var/command in commands)
//Remove leading/trailing whitespace
command=trim(command)
var/list/commandchunks[]=dd_text2list(command," ")
switch(lowertext(commandchunks[1]))
if ("displaymessage")
var/targets[0] //List of targets
switch(lowertext(commandchunks[2]))
if ("src") targets+=src
if ("usr") targets+=usr
if ("view") targets+=view(src)
if ("viewusr") targets+=view(usr)
var/displaywords[0]
for (var/X = 3 to length(commandchunks))
displaywords+=commandchunks[X]
targets << dd_list2text(displaywords, " ")


proc/trim(s)
if(!s) return s
var/i
var/l = length(s)
for(i = 1, i <= l, ++i)
if(text2ascii(s, i) > 32) break
if(i > 1)
if(i > l) return ""
s = copytext(s, i)
for(i = l, i > 0, --i)
if(text2ascii(s, i) > 32) break
if(i < l)
if(i <= 0) return ""
s = copytext(s, 1, i + 1)
return s


There should be an file inside the same directory as the code is in.

Filename : myfilename
File contents: displaymessage src Hey, how ya doin'?