Some questions about building a network-accessible, multi-user, programmable, interactive environment - parsing

Introduction
I've been attempting to build this project for many weeks now, and trying multiple solutions that I can't get my head around. Let me describe the project a little. It's a text-based server, that players can login to (via telnet or a client), essentially like a MUD. They can then create and interact with 'objects', giving them 'verbs' and 'properties'.
The server is basically just a database of 'objects', each object has an ID, a name, a location (which is another object), a list of its contents (objects) and some other flags. Objects can have 'verbs' and 'properties'. Properties are just stored data (string, int, float, w/e). Verbs are methods/functions. Objects are interacted with using commands such as "put something in container". An old version of the server already exists, it's called LambdaMOO. I'm attempting to re-create it since it hasn't been updated in a very, very long time.
You can read more in-depth about how objects, verbs and properties should work at: http://bit.ly/17XIqjY
An Example
Let me describe what I'd like. Imagine we have an object. Object #256, it's called "Button". It has the property "count" along with all the default properties that are inherited from it's parent (i.e. 'description'). It has one "verb" on it, called "push". This verb contains this code:
this.count += 1;
this.description = "This button has been pushed " + this.count + " times.";
player.tell("You press the button and feel a chill run down your spine.");
When the player types 'push button' on the server, the 'push' verb will run and output
You press the button and feel a chill run down your spine.
If you then look at the button, you'll see it's updated description.
Note that player in the above script refers the object of the player executing the verb. tell is another verb, on the player object. However the tell verb has a flag saying it is executable from other verbs.
What language?
My main question is what languages can I use for the 'verbs'? I've tried using node.js and the 'vm' library. I've tried using C# to parse C#. I've tried using C# to parse JavaScript. The issue I keep getting is that I have no way of controlling the permissions of the verbs and properties. If I translate them to literal functions in JavaScript, I can't determine which object they are running on and what permissions it should have. If a user calls a function on another users object, I have no way of intercepting that call and stopping it if the permissions aren't correct. I'm not entirely fussed as to which language is used for the verb code it just needs to be "sandboxed". Properties need to be only readable/writeable when they are set to be so by the user, same with verbs. I imagine I could use a language with overloading (like PHP's __get, __set, __call).
I need to also be able to inject these variables into the verb: (mostly determined from the command typed, unless the verb is being called from another verb)
player (object) the player who typed the command
this (object) the object on which this verb was found
caller (object) this will be the same as ‘player’, unless another
verb calls the command in which case it is the object
containing that verb.
verb (string) the first word of the command
argstr (string) everything after the first word of the command
args (list of strings) a list of the words in ‘argstr’
dobjstr (string) the direct object string found during parsing
dobj (object) the direct object value found during matching
prepstr (string) the prepositional phrase found during parsing
iobjstr (string) the indirect object string
iobj (object) the indirect object value
I also need to be able to access any object from any other object (so long as the permissions work out).
// Object #128. Verb: multiply Prep: this none this Perms: +r +x
return (args[0] * args[1]);
// Object #256. Verb: square Prep: this none this Perms: +r +x
return #128:multiply(args[0], args[0]);
// Object #512. Verb: touch Prep: any any this Perms: +r
// Has a property (int) 'size' on it.
this.size = #256:square(this.size);
this.description = "It's a large button, it spans " + this.size + " metres.";
player:tell("You touch the button, it gets bigger.");
The user could then push button and the button object's size property would be squared.
Recommended Reading
I highly recommend you to read the document at http://bit.ly/17XIqjY for a more in-depth idea of how the system should work.
It is also recommended you read the following documents, as μMOO is based upon LambdaMOO and it’s methodology:
https://en.wikipedia.org/wiki/LambdaMOO
https://en.wikipedia.org/wiki/MOO
http://www.hayseed.net/MOO/manuals/ProgrammersManual_toc.html
http://www.moo.mud.org/

I take this question as asking for a language that could do what you need. That's what I'll try to answer.
First, this task is hopelessly unsuited to any mainstream or imperative language such as C# or Java. I wouldn't even think about it. Javascript is possible, but not what it's good at and nothing specific to recommend it.
Second, if you had the right skills, it would be an excellent opportunity to design an entirely new language and spend the next year or two getting it working. People really do that, but I don't recommend it unless you like that kind of masochistic experience. [I do.]
So my recommendation is that you widen your language experience until you find a match. Of the languages I know moderately well, Ruby is the best to try first. As soon as you said inject these variables into the verb you made me think of Ruby, because lots of Ruby software (including Rails) is built exactly like that. Forget Python, Perl and Javascript: I really don't think they will hack it.
Beyond Ruby you might contemplate Lua. I haven't used it much recently, and it may not suit, but it is widely used as a games scripting language.
Beyond that are the true functional languages. There is the most ancient of them all: Lisp. You can do absolutely anything in Lisp, including implementing the language you were looking for in the first place. Then there are Scala and Haskell, to name just two. They are mind-bending to learn, but well suited to the kind of problem you have.
Not much of an answer because it basically says: learn each of these languages in turn until you find one that works for you. [Happy to help further if I can. I have fond memories of Moo.]

Related

(Roblox scripting) help needed for "GetMaterialColor" or "SetMaterialColor"

I am new to roblox scripting, and I am working on a game. I am trying to make an exploration game with multiple planets. I want the colors on the surfaces of the planets to vary, but I also wish to use smooth terrain, as it is easier to use and looks nice. from reading a bit online, i have figured out i need to use "GetMaterialColor" or "SetMaterialColor". however, "SetMaterialColor", the one i needed specifically, requires two bits of information- the material and the color.
The issue comes from the "Material" part of this, as I have no idea how to make the script recognize what material I want to change. i tried multiple things, including but not limited to:
(grass, #,#,#)
(grass) (#,#,#)
("Grass"), (#,#,#)
("Grass", #,#,#)
or even just (#,#,#), without trying to get a specific material at all
so yeah, I need some help
here is the code:
local function onTouch(hit)
game.Workspace.Terrain:SetMaterialColor
end
script.Parent.Touched:connect(onTouch)
(there should be stuff after SetMaterialColor, that is what i need help with)
If you read the documentation on Terrain:SetMaterialColor(), you'll see that the first argument is a Material type, which is an Enum. So the method expects an Enum (or number to be more accurate), not a string denoting the material.
At the same time the second argument is a Color3, so (#,#,#) isn't apt, using it with the constructor Color3.fromRGB(#,#,#) is. If you are ever confused about what a method returns or expects, try referring to its documentation on https://developer.roblox.com/.
Here's an example of correct usage:
workspace.Terrain:SetMaterialColor(Enum.Material.Grass, Color3.fromRGB(123,123,123))
And ofcourse, Event:Connect() instead of Event:connect()

Where is 's' object cached when using AppMeasurement in DTM

Omniture's basic page tracking function, s.t(), was not crafted for AJAX implementation. Unlike the onclick s.tl() function which has some gating instructions with s.linkTrackVars and s.linkTrackEvents, the s.t() function just perpetuates every cached property through to the next call and beyond.
I used to be able to use a ClearVars function to empty out all of the s object's attributes, but now that I am using AppMeasurement and letting DTM manage my implementation with the most updated version of that library—which I want to keep doing—I can't call the s object. I get the same "ReferenceError: s is not defined" that another person asked about here!.
I tried following Crayon Violent's instructions within that post, but I can't seem to find where DTM is stashing the cached values in between Adobe calls. This code:
window.s = new AppMeasurement();
lets me change/clear the attributes of s, but it's not the s I'm looking for. When I call the next AJAX s.t() function, all of the cached values are still there.
In my experience working with DTM and AA, there has been no end to bugs and caveats and workarounds with DTM's "native integration" of AA. This is why I have more or less decided that the best thing I can do is to either manage the lib myself or else treat AA as a 3rd party script (100% implement it through rules, just ignore that it's available as a tool).
As mentioned in my answer you linked, that line of code only works to expose the AA object in the window namespace if you are managing the library yourself. When you configure DTM to manage the library, it will instantiate AA object itself, and it will be buried within its own code (Honestly, I don't know why DTM did this, considering AA puts a number of other variables in the global namespace that DTM does nothing about).
AFAIK there is no documented way to reference it, but one thing I have found that seems to work for me - which as a disclaimer to cover my own arse I do NOT officially endorse: use at your own risk - is to use the following to get a reference of it:
var s = _satellite.getToolsByType('sc')[0].getS();
This uses getToolsByType method to get an array of the SiteCatalyst (Adobe Analytics) objects setup as tools in DTM. It does this by looping through _satellite.tools and comparing _satellite.tools[n].settings.engine to what you passed to getToolsByType.
Then I use [0] to get the first one in the array, under the assumption that there's only one configured (most people only do one). Then the getS() object pulls together the s object based on the settings in DTM. So from there, you can do things with it, including making use of s.clearVars()

How do I construct the cake when using Scalaxb to connect to a SOAP service?

I've read the documentation, but what I need to know is:
I'm not using a fictitious stock quote service (with an imaginary wsdl file). I'm using a different service with a different name.
Where, among the thousands and thousands of lines of code that have been generated, will I find the Scala trait(s) that I need to put together that correspond to this line in the documentation's example:
val service = (new stockquote.StockQuoteSoap12Bindings with scalaxb.SoapClients with scalaxb.DispatchHttpClients {}).service
Now, you might be thinking "Why not just search for Soap12Bindings in the generated code"? Good idea - but that turns up 0 results.
The example in the documentation is outdated, or too specific. (The documentation is also internally inconsistent and inconsistent with the actual filenames output with scalaxb.)
First, search for SoapBindings instead of Soap12Bindings to find the service-specific trait (the first trait).
Then, instead of scalaxb.SoapClients, use scalaxb.Soap11Clients.

Does this Rails 3 Controller method make me look fat?

This is a new application, and I have an index method on a Search controller. This also serves as the home page for the application, and I'm trying to decide if I am headed down the wrong path from a design pattern perspective.
The method is already 35 lines long. Here is what the method does:
3 lines of setting variables to determine what "level" of hierarchical data is being searched.
Another 10 lines to populate some view variables based on whether a subdomain was in the request or not.
A 10 line section to redirect to one of two pages based on:
1) If the user does not have access, and is signed in, and has not yet requested access, tell them "click here to request access to this brand".
2) If the user does not have access, is signed in, and has already requested access, tell them "so and so is reviewing your request".
Another 10 lines to build the dynamic arel.
I can't get it straight in my head how to separate these concerns, or even if they should be separated. I appreciate any help you can offer!
Summarizing what you've said in something codelike (sorry, don't know ruby; consider it pseudocode):
void index() {
establishHierarchyLevel();
if (requestIncludedSubdomain())
fillSubdomainFields();
else
fillNonsubdomainFields();
if (user.isSignedIn() && !user.hasAccess()) {
if (user.hasRequestedAccess())
letUserIn();
else
adviseUserOfRequestUnderReview();
}
buildDynamicArelWhateverThatIs();
}
14 lines instead of 35 (of course, the bodies of the extracted methods will lengthen the overall code, but you can look at this and know what it's doing). Is it worth doing? That really depends on whether it's clearer to you or subsequent programmers. My guess is it's worth doing, that splitting out little code blocks into their own method will make the code easier to maintain.
That's a lot of variables being set. Maybe this is a good opportunity for a module of some kind? Perhaps your module can make a lot of these decisions for you, as well as acting as a wrapper for a lot of these variables. Sorry I don't have a more specific answer.
Without your code it's somewhat difficult to suggest actual fixes, but it definitely sounds like a really wrong approach and that you're making things much harder than they need to be:
3 lines of setting variables to
determine what "level" of hierarchical
data is being searched
if there is a search form, I would think you would want to pass those straight from the params hash into scopes or Model.where() calls. Setup scopes on your model as appropriate.
Another 10 lines to populate some view variables based on whether a subdomain was in the request or not.
This seems to me like it should be at most 1 line. or that in your view, you should use if statements to change what you'd like your output to be depending on your subdomain.
A 10 line section to redirect to one of two pages based on:
the only thing different in your explanation of the 2 views is "whether the user has requested access" surely this is just a boolean variable? You only need 1 view. Wrap the differences into 2 partials and then in your view and write one if statement to choose between them.
Another 10 lines to build the dynamic arel.
It might be necessary to go into Arel, but I highly highly doubt it. Your actual search call can in most cases (and should aim to be) 1 line, done through the standard ActiveRecord query interface. You want to setup strong scopes in your models that take care of joining to other models/narrowing conditions, etc. through the ActiveRecord Query interface.

Capturing Field Name Metadata from a CSV File in Altova MapForce

I've been asked to prototype a replacement "file transformation process" (that currently is a mess of SQL) using Altova's MapForce. My input is a CSV file with headers. My problem is that I need to capture both the data AND the column name to use in downstream processing.
I need to have MapForce feed a C# method (imported as that takes two parameters: fieldName and value. I can access the value trivially, but after hours pouring over the manual (1000 pages!) I haven't found any examples of how to access the field name as an output.
The reason each output needs the field name and the value has to do with how all our mappings/transformations are currently managed - on a database. The .NET code jumps in at this point and does any necessary database lookups.
For example, if I had the following file:
"Symbol", "Account", "Price", ...
"FOO", "10101", "1.23", ...
"BAR", "10201, "13.56", ...
And a static method string TransformField( string fieldName, string value ),
I'd like to map the CSV file's Symbol data output to the method's value parameter and the Field Name "Symbol" to the method's fieldName parameter.
Some limitations:
I need to keep the "wiring" visible in the MapForce GUI. I'll have non-programmers maintaining the mappings in the future. So doing all this in code is not an option.
MapForce is the tool of choice by the company. Part of the reason our original process is such a mess is because the original programmer rolled his own mapping/transformation tool (out of TSQL no less - ouch).
We can treat all inputs/outputs to the method call as strings. Conversions will happen later.
I would like to avoid using scalar literals as inputs. I already have the column names from the file - I do not want to re-type each one and feed it to my method.
I'm not sure how many users out there have experience with this tool, but after 3 days of tinkering with it, I see much potential. If only I can get past this current sticking point, I think the company will have a solid alternative to their current mess.
Thanks for any/all suggestions.
I solved my issue and, for future reference, want to post a solution. I handled my problem by using MapForce's FlexText. This allowed me to extract the header from the CSV file and "invert" the column names as data inputs to the transformation process. Once I knew the approach to take, I was able to find more information directly from Altova.
I found a couple helpful tutorials while digging through their website:
Altova Online Videos
Web Tutorial
Hope this can help someone else in the future!

Resources