This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
oeed's profile picture

Quest/CCML Mega-Tutorial

Started by oeed, 04 November 2014 - 06:06 AM
oeed #1
Posted 04 November 2014 - 07:06 AM
For more information about Quest and the download link check out this topic.

This is going to be another fairly large tutorial. If you haven’t already seen it, you should checkout Quest. Simply put, it’s an HTML(ish) web browser which functions as close to a standard web browser as I could realistically make it in ComputerCraft given the screen space, storage space, character size and HTTP limitations that exist. You can use things like PHP, Node.JS, or even ASP if you’re strange enough. You can also make plain old static web pages, which is where we will start.

Even if you’ve made tons of HTML pages before, there are a number of notable differences. However, I’ve tried to make everything as close as possible to HTML, you’d be rather surprised how much is identical. In fact, if you haven’t used HTML before I’d recommend learning the basics somewhere else first, I’m going to be fairly specific about the differences rather than teaching from scratch.

Creating Your First PageThe first and most important difference when creating a page is the doctype. In most cases you’ve probably haven’t really touched the page doctype. When creating a CCML page (the special for of HTML for Quest) you must set the page doctype. If you don’t the page simply won’t load, it’ll just give an error. This is to prevent normal web pages loading and screwing up/crashing the browser.

In terms of storing/hosting this page, you have a few options. The first and probably best way at this stage is to just create a file called index.ccml on your computer and edit that. You could also use Quest Host or host it on your own server, but it’s quicker an easier to just store it on the computer.

So, here’s a basic page template, it doesn’t have much at this stage, but it will help you get started.

<!DOCTYPE ccml>
<html>
<head>
<title>Welcome to your website!</title>
</head>

<body>
<br>
<h>Welcome to your website!</h>
<br>
<p width="46" align="center">
Paragraph text.
</p>
</body>
</html>

You’ll notice that the heading isn’t called h1, h2, etc. Due to the fact that you cannot have multiple font sizes in ComputerCraft there isn’t really a need for multiple heading sizes. By default headings are full width and centred.

You’ll notice that there isn’t any CSS. I feel like it’s over complex for what needs to be displayed, so at this stage everything is done using attributes. The next section explains them in greater depth.

Using Element AttributesAs mentioned in the previous section, how elements look is determined by element attributes, not CSS. Most elements within the body take the following attributes:
Note: color can also be used instead of colour, you don’t need to use the British spelling.

colour (text colour)
bgcolour (background colour)
height
width

You can use the colour attributes like this:

<p bgcolour="red" colour="white">
Paragraph text.
</p>

Sometimes setting height doesn’t actually set the element height, if you need to use a set height try wrapping the element with a div.

Here is a list of pretty much all the available elements and the attributes they accept. * indicates that the attribute must be supplied

div:
- char (the background character, useful for creating splitters with ‘-‘, for example)

float, p, h, a:
- align (text align, accepts: ‘left’, ‘right’ or ‘center’)

input:
- type * (the same as it is in normal HTML, accepts: ‘text’, ‘password’, ‘submit’, 'hidden', 'file')
- name * (same as in normal HTML)
- value (same as in normal HTML)

input (text &amp; password):
- placeholder (placeholder text when the value is empty)
- plcolour (colour of the placeholder text)
- selcolour (colour of selected text)
- selbgcolour (background colour of selected text)

select:
- value (same as in normal HTML, sets selected option [use the option value, not text])

option:
- value (same as in normal HTML, the value when submitted, not the shown text)

a:
- href * (same as normal HTML, doesn’t accept anchor tags yet)
- ulcolour (the link underline colour, accepts all colours and ‘none’)

img:
- src * (same as normal HTML)
- type * (the image format, accepts: ‘nfp’ (or ‘paint’), ‘nft’ or ‘skch’ (or ‘sketch’)

center, br:
- no special attributes

form:
- action (same as HTML)
- method (same as HTML, accepts: ‘post’ and ‘get’)


Some attributes will be explained in greater detail in later sections, but most of them function pretty much identically to HTML.

Making a Wi-Fi ServerI'll add this soon, just need to get a few screenies!

Creating LinksLinks but the net in internet, the webs in interwebs, and the web in web. In other words, they’re pretty useful.

Links in CCML function pretty much identically to as they do normally, you can use absolute URLs (e.g. http://computercraft.info/forms2/) and relative URLs (e.g. /mypage.ccml or mypage.ccml).

You can’t yet use page anchors, but if there’s demand for them I might add them.

Links also accept the ulcolour attribute. This sets the underline colour of the link, you can also use ‘none’ which will remove the underline completely making the element one pixel high rather than two.

By default links take up 100% width and align to the left, you can use the related attributes to change this.

If you need any other help with links take a look at how HTML links work, they’re almost identical.

Creating ImagesImages in Quest are pretty similar to standard HTML images. The biggest difference is obviously the image format.

Quest supports the three main image formats, NFP (the paint image format), NFT and Sketch. If you want to edit or create images I’d recommend using my Sketch program, it supports all those formats.

While you don’t have to set the image type you certainly should if you know it. It will try to guess, but it’s not perfect, especially NFP and NFT formats.

To set the format use the type attribute, like below.


<img src="logo.nft" type="nft" width="10" height="8"/>

<img src="logo.nfp" type="nfp" width="10" height="8"/>

<img src="logo.skch" type="sketch" width="10" height="8"/>

You should also set the width and height of the image if you can. If you don’t while the image is loading the image will show as 1 x 1, then when the image loads it will have to change size and bump all the page content down, as it does with normal HTML.

The image location supports relative and absolute URL.

Center ElementsFor elements that aren’t 100% width and don’t have align attributes, such as paragraphs, you can use the center tag. This works similar to how the center tag worked in older versions of HTML. It essentially centers all immediate child elements (it won’t center elements within another element). If you’re finding it’s not working, chances are the object is set to 100% width.


<center>
<p width="30">I’m paragraph text. Notice that text isn’t centred, only the paragraph is.</a>
<input type="submit">I’m a Button</input>
</center>

Inline Elements/FloatsBy default all elements require the entire line, they’re like block elements in CSS. There is no display or inline attribute, but you can use a special wrapper element called float. Essentially, what it does is makes all it’s immediate children "float" (as in CSS float: left, etc.) They will line up side by side. Some elements though, such as links, headings and paragraphs will automatically set their width to 100%, if you put one of these within a float you need to manually set it’s width, otherwise the other elements will wrap around.

It takes a little to get used to but it’s quite an easy way of doing things.

For example, to create a basic navigation bar you can use this code, make sure you set the width of the links, by default they’re 100% width.


<float>
<a href="index.ccml" width="6">Home</a>
<a href="index.ccml" width="7">Pages</a>
<a href="index.ccml" width="7">About</a>
</float>

You can also set the align to left or right, by default it is left.


<float align="right">
...
</float>

FormsForms are pretty much identical to HTML forms. You can use both GET and POST (although GET may be a little buggy on som servers due to how sessions work). To get the full benefit of forms you really need to use something like PHP to access the values.

At the moment Quest supports the following input types: submit, text, password, file, hidden

The hidden element is just a hidden value, it's useful if you need to put something on the page (Quest Host uses it for the current folder path) that you don't want the user to see or change.

Files are handled differently due to limitations of the HTTP API, there's another section about them below.


<form action="mypage.php" method="post">
<input type="text" name="q" placeholder="Search"/>
<input type="submit" name="submit"/>
</form>

If you've used HTML forms before you should be pretty comfortable with using them.

It's also worth noting that all passwords are hashed with SHA256 before they leave the browser for security. However, this doesn't mean you shouldn't also salt and rehash the password! It's just to prevent… hmm, how do I put this… slightly less competient, slightly more stupid people or rather malcious people from releasing your password, either intentionally or accidentally.

You can also set the align to left or right, by default it is left.

File UploadingThis is where things start to become a little wonky and hacky. Because the ComputerCraft HTTP API doesn't support binary there's no multipart data or anything like that.

So, to combat this I've had to make a substitute system.
It uses either POST or GET, depending on which method you set it to, but it's probably best to use POST for files to prevent accidental reuploading or file mutation.


<form method="post">
<input type="file" name="upload-file"/>
<input type="submit" name="submit"/>
</form>


if (isset($_POST['upload-file'])) { //you probably also want:  &amp;&amp; isset($_POST['submit']) for completness
$upload = json_decode(stripslashes($_POST['upload-file']), true);
if(!$upload || !$upload['name'] || !$upload['content']){
//upload was ok
//the name of the file is ['name'] and the file content is ['content']
}
else{
//upload failed
}
}

Basically, it uploads some JSON with the name and content. The above example is obviously PHP, but it shouldn't be to hard to convert to other languages.

LuaScript/lQueryI'm still working on this, it works but it's pretty incomplete. I'll add a tutorial about it when it's ready.
Edited on 04 November 2014 - 08:46 AM
TheEvilSocks #2
Posted 11 November 2014 - 01:24 PM
Man I love this already!

Is there a way to make (mysql) databases?

EDIT:
Also, do cookies work? I can't get them to work.
Edited on 11 November 2014 - 12:32 PM
oeed #3
Posted 11 November 2014 - 08:55 PM
Man I love this already!

Is there a way to make (mysql) databases?

EDIT:
Also, do cookies work? I can't get them to work.
If you use a web server that has MySQL then yes.

Cookies don't work, although I made a substitute. However, it looks like I forgot that section. I'll try and write it up today.
deletedededed #4
Posted 17 November 2014 - 01:26 AM
Thanks for the help, I've been trying to get a "Center tag" working for a long time, If only I could understand lua this fluently.
willwac #5
Posted 19 November 2014 - 12:00 AM
I'm putting this on GitHub
superkiller4456 #6
Posted 19 January 2015 - 03:03 AM
I want to make a small website so it lists different lines of text.
but i also want to make it so i can submit a text to from the same site.
any help?
dueckers5 #7
Posted 31 January 2015 - 06:03 AM
You should make it so much simpler to use! I READ IT ALL and im still confused! Try making a video
MKlegoman357 #8
Posted 31 January 2015 - 05:13 PM
What's so confusing? It's pretty much basic HTML.
Rougeminner #9
Posted 26 February 2015 - 10:30 PM
You should make it so much simpler to use! I READ IT ALL and im still confused! Try making a video

I will help u where you need it just please PM me on my account page. sorry i have no vid though
_removed #10
Posted 19 April 2015 - 03:42 PM
Wait a minute, This can connect to real webpages? So I can have a webpage on the internet?
KingofGamesYami #11
Posted 19 April 2015 - 03:57 PM
Yeah, but it won't parse normal HTML, and normal browsers won't be able to parse CCML.
MKlegoman357 #12
Posted 19 April 2015 - 05:11 PM
Do note that you can very easily make any existing webpage work with Quest. By default, Quest searches for files ended with .ccml, so you can have an index.html for your main webpage and an index.ccml for Quest main page.
biggest yikes #13
Posted 25 April 2015 - 12:33 AM
Still no LuaScript tutorial? :(/>
I know it exists, this code is valid..

<head>
<title>Is LuaScript supported?</title>
<script type="lua">
  l('p').text("Luascript is supported!")
</script>
</head>
<body>
  <p width="48">LuaScript is not supported; update Quest!</p>
</body>
EDIT: Figured it out, it's basically just a sandboxed lua environment that has a few special functions, a "window" table, and the "l" (L) function to set the text of elements and such.
Edited on 26 April 2015 - 01:27 PM
Fetchetch #14
Posted 02 May 2015 - 05:31 PM
So from what the app is saying, to use PHP you need to host it off of your own server.
What would be a way to host it off of a web server? (e.g. change
253 local questHost = 'http://quest.net76.net/sites/'
to
253 local questHost = 'http://somewebserver.net/sitedir/'
)

I did try that using 000webhost but i only got error code 2 (incorrect doctype) every time i load a page.

Edit 1: Also, how would a user download a file? By linking it? (e.g.
<a href="example.txt">example</a>
) and it would download?
Edited on 02 May 2015 - 05:05 PM
Lignum #15
Posted 03 May 2015 - 03:36 PM
I did try that using 000webhost but i only got error code 2 (incorrect doctype) every time i load a page.

Add <!DOCTYPE ccml> at the top of your ccml file.

Edit 1: Also, how would a user download a file? By linking it? (e.g.
<a href="example.txt">example</a>
) and it would download?

Yes, that should work.
biggest yikes #16
Posted 03 May 2015 - 08:53 PM
So from what the app is saying, to use PHP you need to host it off of your own server.
What would be a way to host it off of a web server? (e.g. change
253 local questHost = 'http://quest.net76.net/sites/'
to
253 local questHost = 'http://somewebserver.net/sitedir/'
)
If you do that, then the ".qst" domain will direct to your website instead. To access your webpage, all you need to do is type the URL into your address bar. (Doesn't work for some webpages, like Github, because they don't function with post requests).
Yes, to use PHP you have to host the PHP files on your own server.

-snip-
I did try that using 000webhost but i only got error code 2 (incorrect doctype) every time i load a page.
CCML has an extremely strict format. In your case, the first line in your HTML document MUST be "<!DOCTYPE ccml>", or else it refuses to load. If you're using PHP, before you begin your PHP code (<?php), put <!DOCTYPE ccml>, like this:

<!DOCTYPE ccml>
<?php
myphpcode
?>

Edit 1: Also, how would a user download a file? By linking it? (e.g.
<a href="example.txt">example</a>
) and it would download?
If you click a link and the file extension isn't ccml, html, php, asp, aspx, jsp, qst, com, me, net, info, au, or nz, it'll download it automatically. ".txt" will automatically download, so in that case if the user clicked "example" it would indeed download the file "example.txt".
Edited on 03 May 2015 - 07:05 PM
Piorjade #17
Posted 18 October 2015 - 01:25 AM
Am I stupid or why does the file "test.php" not work on Quest:
<!DOCTYPE ccml>
<?php
echo "Hello World";

?>

It just gives me the error: WebView (Bedrock API):19: attempt to index ? (a nil value)
Konlab #18
Posted 18 October 2015 - 02:02 PM
Am I stupid or why does the file "test.php" not work on Quest:
<!DOCTYPE ccml>
<?php
echo "Hello World";

?>

It just gives me the error: WebView (Bedrock API):19: attempt to index ? (a nil value)
Php is a server side language. It is executed on the server. Quest gets only HTML, not PHP.
Edit: Are you using a custom server? Or oeed's hosting (no php support when using this)
Edited on 18 October 2015 - 12:06 PM
oeed #19
Posted 18 October 2015 - 09:58 PM
Am I stupid or why does the file "test.php" not work on Quest:
<!DOCTYPE ccml>
<?php
echo "Hello World";

?>

It just gives me the error: WebView (Bedrock API):19: attempt to index ? (a nil value)
Php is a server side language. It is executed on the server. Quest gets only HTML, not PHP.
Edit: Are you using a custom server? Or oeed's hosting (no php support when using this)

Just to point out, PHP does work in the normal fashion. Whilst it is server side, it should be sending the CCML as normal.

I think the issue is your code is missing a <p> tag. The Quest HTML renderer is pretty terrible and doesn't just support text anywhere. I think you probably also need the <html> and <body> tags, checkout the main tutorial.
Piorjade #20
Posted 23 October 2015 - 02:41 PM
I tried it with the <html> and <body> tags, this time it does not show the error but just shows nothing.
And I'm using 000webhost. (I tested the code in a real browser and it works, as expected.)

Here the code:



<!DOCTYPE ccml>
<html>
<head>
<title>TestSite</title>
</head>

<body>

<br>

<h> Test </h>

<br>

<p width="46" align="center">
Test
</p>

<br>

<?php
echo "Hello World";
?>

<br>

</body>

</html>


So when i try to get to the site it shows the normal HTML code ("Test" and "Test") but then no "Hello World" and no error.

Ohhhh i tried the <p> tag and now it worked :o/>/>
Thx oeed. :)/>/>
Piorjade #21
Posted 05 December 2015 - 04:04 PM
Somehow i can't get uploading to work… So my question is if you would make a remake or improve it after CraftOS 2.0 has been released?
oeed #22
Posted 06 December 2015 - 12:01 AM
Somehow i can't get uploading to work… So my question is if you would make a remake or improve it after CraftOS 2.0 has been released?

Yeah, it's a bit of broken mess.

I will probably remake it after CraftOS 2.0 is released if time permits. It should be a lot better and 'proper' because Dan has fleshed out the HTTP API.
Piorjade #23
Posted 13 December 2015 - 01:48 PM
Nice
Tobias SN #24
Posted 19 January 2016 - 09:05 AM
Is it possible to have repeaters that would allow for further range of access for an in-game server due to the limited range of rednet (Around 65 blocks)
Xbox360Guy #25
Posted 16 September 2016 - 11:28 PM
How do i edit?
Bomb Bloke #26
Posted 17 September 2016 - 01:24 AM
You may simply use Notepad to edit web page documents, as they consist of raw text. Or most any other text editor. If it'll suffice for Lua scripts it'll suffice for this.