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

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()

Related

Measuring the height of text according to CSS rules – _without a browser rendering_ – for use with a virtualized list, to specify heights in advance

I've been implementing a chat client in Electron (Chrome) and React. Our top priority is speed. It behooves us, then, to use a virtualized list component (also known as "buffered render" or "window render"). We've explored react-virtualized, react-window, and react-infinite, among others.
One issue all these components have in common is that if supporting list elements of variable heights, the heights need to be known in advance. Now, some chats are very long, and others are very short, so that presents a challenge for us. (Images and video are easy thanks to EXIF data and ffprobe).
So, we're faced with the challenge of measuring heights while also straining to be extremely performant. One obvious technique is to put the elements in a browser container off-viewport, perform the measurements, and then render the list. But that hurts us on the performance requirement aspect. Software like react-virtualized/CellMeasurer (which is no longer maintained by the original author) and react-window make us of this technique, built in to the library, but performance is somewhat slow as well as unreliable. A similar idea that might be more performant would be to use a background Electron Browser window to do the rendering and measuring, but my intuition is that wouldn't be that much faster.
I submit that there must be some solved way to figure out string height in advance, according to word wrap, max width, and font rules.
My current idea is to use a library like string-pixel-width in order to calculate row heights as soon as we get the text data through our API. Basically, the library uses this piece of code to generate a map of character widths [*]. Then, once we know how wide each text, we separate each line when it maxes out the computed max row width, and finally infer list element height through row count. It's going to require a little bit of algorithmic fiddling due to break-word but there are libraries to help with that – css-line-break seems promising.
[*] We would have to modify it a bit to account for all Unicode character ranges, but that is trivial.
Some options I haven't fully explored yet include the python weasyprint project and the facebook-yoga project. I'm open to your ideas!
Using the canvas capabilities to measure text could solve this problem in a performant way.
Electrons canvas text is calculated the same as the regular text, there are some diffrences in rendering though especially in reguard of anti-aliasing but that does not affect the calculation.
You can get the TextMetrics from any text with
const canvas = document.getElementById('canvas')
const ctx = canvas.getContext('2d')
// Set your font parameters
// Docs: https://developer.mozilla.org/en-US/docs/Web/CSS/font
ctx.font = "30px Arial";
// returns a TextMetrics object
// Docs: https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics
const text = ctx.measureText('Hello world')
This does not include line breaks and word wraps, for this feature I would recommend you to use the text package from pixijs, it uses this method already. In addition you could fork the source (MIT licence) and modify it for additional performance by enabling the experimental chromium TextMetrics features in electron and make use of it.
This can be done when creating a window
new BrowserWindow({
// ... rest of your window config ...
webPreferences: {
experimentalFeatures: true
}
})
Now to the part I mentioned in the comments since I don't know your codebase, your calculations and everything should be happening in the Render Process. If that is not the case you definitely should move your code from the main process over to the render process, if you do file access operations or anything node specific you should still do this but in a so-called preload script
it's a additional parameter in the webPreferences
webPreferences: {
preload: path.join(__dirname, 'preload.js')
experimentalFeatures: true
}
In this script you have full access to node including native node modules without the use of IPC calls. The reason I discourage IPC calls for any type of function that gets called multiple times is that it is slow by nature, you need to serialize/deserialize to make them work. The default behaviour for electron is even worse since it uses JSON, except you use ArrayBuffers.

Rails - Pass multiple text_fields as parameters

I've read everything I can on forms and such and they never seem to work the way I want them to.
As a work around, I'm trying to pass a series of parameters to my controller via remote: true and javascript. I've got a solid foundation working.
I can't think of a proper way to explain this without getting too crazy, so I'll just explain what I am doing.
Goal-
I have a FlashCard model going. The flash cards each have: Title, lines(7) and a body. The body is represented as the back of the card. The front of the card consists of the title and 7 lines. Each line can be written on individually and optionally centered. The card can be formatted as either read or write. Obviously read is a read-only and write gives you the ability to change whether or not each line is centered, and change/add the text on the title, each line, and the body.
Now. I probably chose a bad way to do this, but it's how I chose to do it. I have an affinity towards arrays so I tend to use those when in doubt.
My flash card model has title:string, line:string as array, and body:text.
The line is formatted as follows: [["",0],["",0],["",0],["",0],["",0],["",0],["",0]]
The strings are the string on each line and the 0's can be either 0 or 1, as false and true- representing whether or not the text on that line is centered.
As far as displaying all of this, I have it working just fine. However- actually saving the data is proving to be a problem. Forms are not working out for me because of the line array/attribute. I don't mind doing the logic myself without the form, but I need a way to pass the data from the text_fields to the controller to save them.
Hopefully that makes sense. If not- I will happily add in the code I have used to get to where I am and more specifically show where I am having problems.
Optimally, I would like to simply pass the strings from multiple text_fields as separate parameters to the controller. If necessary to go back and entirely redo the model, I will do so if it will work as long as I can get the same functionality.
Thanks in advance for the help!

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

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

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.

ASP.NET Routing Question

Why is this:
http://MySite.com/Project/24/Search/32/Edit/49
preferred over this?
http://MySite.com/Project/24?Search=32&Edit=49
I'm not sure where your premise is coming from? It looks like an artificial example, which makes it hard to comment on.
A better comparison would be something like:
http://MySite.com/Project/24/Members/Edit
As opposed to:
http://MySite.com/Projects.aspx?id=24&section=Members&action=Edit
Where, among other things, the hierarchy of entities is immediately obvious from the first example (ie, a Project contains Members). It also suggests that you can use other URLs that contain similar structures to the first (ie, /Projects/24 and /Projects/24/Members), so in that sense it's more concise.
If it comes down to actions that have a variable number of parameters, such as searching, then it's totally fine to use URL parameters as this will give you more flexibility, eg:
http://MySite.com/Projects/Search?name=KillerApp&type=NET
You could construct a URL using the first style, but you don't really gain anything, and managing the route could add unnecessary overhead:
http://MySite.com/Projects/Search/name/KillerApp/type/NET
I would argue that this (or any similar construction, eg if you removed the param names) suffers from an artificial hierarchy - the action in this case is really Search, and everything else is just a parameter of the Search, so it's in the same hierarchy, not some "sub" hierarchy.
Not really a fair comparison. The style allows you to drop the GET parameter names, so the routed one should read something like
http://MySite.com/Project/24/32/49
It's really an aesthetic improvement, though -- it's both neater-looking, and easier to type or read out to someone.
Its mostly a human readability issue, although (since most search engine ranking algorithms are not publically disclosed), it is believed to have SEO value as well.
In the example case, it may not be any better. But it's a Search Engine Optimization in general. Here are some SEO best practices -- from that article ...
Ideally, the URL structures should be
static, and reveal what the page is
about. A simple and clear URL
structure is much easier for both
search engine spiders and human
beings.
Easier to remember as well. It's easier for a user to remember /Employee/1 to get the information for employee #1 rather than understand a querystring. Not a reason to use it but I think its a small improvement.

Resources