This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2011-11-10 16:24:22

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Web-languages: Help and helper thread

@windowsexplorer, is this the script you used on your website? not workng on FF7 :S

Offline

 

#27 2011-11-10 16:32:21

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web-languages: Help and helper thread

roijac wrote:

@windowsexplorer, is this the script you used on your website? not workng on FF7 :S

yes http://www.plaxon.comyr.com/login.php (this website is approved by scratch, so its okay!)


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#28 2011-11-10 16:35:35

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Web-languages: Help and helper thread

@WindowsExplorer Actually, it can be the registration script as well. Make sure your passwords are being hashed ( so check the database ) then check if they are being checked properly. You will also want to make sure there is enough space in the database ( the limit to the size of data in a column ) is large enough to hold the hashed password. You need to make sure all the input you are giving is correct and then you check the code and make sure all the commands are in the correct order and it's written properly.

So do that then, if you can't fix it, come tell me or someone else and tell us all the info you have found, ( Like the echo'd username and password and hashed password, make sure the account is a test one. ) and give us the code for the registration and login code.

Offline

 

#29 2011-11-11 07:42:50

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

^ Home
JavaScript Objects Part I: Introduction and Properties
Difficulty: Moderate
[Part I] [Part II] [Part III]

JavaScript is an object-oriented language. This means it uses the concept of objects. Think of objects as exactly what it is: an object. It could be a button, a window, or something more abstract like a piece of text or a list. Every object you see has properties, like a color or texture. Buttons have text, windows have sizes, text has its length, etc.
An object is accessed by creating an instance. An instance of a window object is the window you're viewing right now; an instance of the string object could be any piece of text in a piece of JavaScript.
Properties of objects are accessed through two syntaxes: the dot syntax and the square bracket syntax.
Here's an example where we get the property property from object OBJECT.

Code:

// Dot syntax:
OBJECT.property

// Square bracket syntax
OBJECT["property"]

Notice how the square bracket syntax makes you put the property name in quotes. That's because the name is a string. You can also insert variables there:

Code:

var something="property";
OBJECT[something]

Now some real examples!
The JavaScript string object is a piece of text. It is declared with the syntax:

Code:

var myString = "A String";

Now, the string object has the length property, which returns the number of characters.

Code:

var string = "string";
alert(string.length);// alerts 6

^ Home

Last edited by Hardmath123 (2011-11-11 10:52:05)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#30 2011-11-11 09:23:12

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

Thanks Hardmath  smile  That's a good tutorial! I learnt something new about Javascript myself!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#31 2011-11-11 09:47:46

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

sparks wrote:

Thanks Hardmath  smile  That's a good tutorial! I learnt something new about Javascript myself!

Thanks, a Part II (methods) and Part III (custom objects) are coming up soon.  smile
PS My advice: start on stats now. Otherwise you'll have too many posts to deal with later. That's what happened to the block library, I think. Too many posts...  wink


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#32 2011-11-11 09:57:18

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

^ Home
JavaScript Objects Part II: Methods
Difficulty: Moderate
[Part I] [Part II] [Part III]
Methods are like verbs: they dictate actions. So, a balloon can have the pop method. Methods take arguments, which are inputs (how loud should it pop?). They also sometimes return outputs (how many people got scared?).
Here is the general format:

Code:

OBJECT.method(argument1, argument2, ...)

For ones that return values, it's not much different:

Code:

alert(OBJECT.method(argument1, argument2, ...));

Here's the balloon example:

Code:

alert(balloon.pop(100)+" people got scared by a level 100 pop!");

Did you know alert() is a method of the window object? It's true! The correct syntax is window.alert(), alert() is a shorthand.
Now for the last, "real-world" example: the charAt() method of the string object:

Code:

alert("Hi!".charAt(1));//Note that charAt(0)=1st character...

^ Home

Last edited by Hardmath123 (2011-11-11 10:47:54)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#33 2011-11-11 10:05:29

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

^Home

Statistics

Total number of shared tutorials: [5]

HTML tutorials
WindowsExplorer [1]

PHP Tutorials
Sparks [1]

Javascript tutorials
Hardmath123 [3]

^Home

Last edited by sparks (2011-11-11 12:18:58)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#34 2011-11-11 10:09:23

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

^ Home
JavaScript Objects Part III: Custom Objects
Difficulty: Moderate
[Part I] [Part II] [Part III]
There are, in the end, a limited number of JavaScript objects out-of-the-box. But you can make your own. In this example, we will make a sprite object, with properties and methods.
An object is declared like a function:

Code:

function sprite()
{
}

An instance is created with the code:

Code:

var sprite1 = new sprite();

Properties are added by using the this object. this is the instance of the object.

Code:

function sprite()
{
 this.xposition = 0;
}

Now, you can access this property:

Code:

var sprite1=new sprite();
alert(sprite1.xposition);
// Or change it:
var sprite1=new sprite();
sprite1.xposition = 5;

But what if you want a customized sprite directly, without changing them individually? You use startup parameters.

Code:

function sprite(xpos)
{
 this.xposition=xpos;
}
// And the instance:
var sprite1=new sprite(5);

Finally, methods are added as properties, but the value is a function rather than a number or string:

Code:

function sprite(xpos)
{
 this.xposition=xpos;
 this.move=function()
 {
  this.xposition=this.xposition+5;
 }
}
//And the instance:
sprite1.move()

Note that sprite1.move [no brackets] will report the function, unevaluated.
^ Home

Last edited by Hardmath123 (2011-11-11 10:55:15)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#35 2011-11-11 10:15:51

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

^Home

Tips for writing a good tutorial

Format
Use the following format to make sure your tutorial fits the others in this thread:

Code:

[url=http://scratch.mit.edu/forums/viewtopic.php?pid=991961#p991961]^ Home[/url]
[b]Title[/b]
Difficulty: [color=green/orange/red][b]Easy/Moderate/Hard[/b][/color]
YOUR TUTORIAL...
[url=http://scratch.mit.edu/forums/viewtopic.php?pid=991961#p991961]^ Home[/url]

~Tip shared by Hardmath123

Good tips
     - Do your best to explain everything you show in as much detail as possible so that
       no-one misunderstands what to do and is left confused.
     - Use proper English rather than shorthand or slang when typing or you risk people
       being unable to read what you're written.
     - Link to external sources where you do not explain something, for example ]
       abbreviated words like GUI or API or when detailing parts of a tutorial users should
       know about but you do not explain like strtolower or other commands.

These tips will allow other people to get the most out of your tutorial so consider sticking by them!

^Home

Last edited by sparks (2011-11-11 11:21:47)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#36 2011-11-11 10:24:20

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

Format: (You may want to add this to the above post)

Code:

[url=http://scratch.mit.edu/forums/viewtopic.php?pid=991961#p991961]^ Home[/url]
[b]Title[/b]
Difficulty: [color=green/orange/red][b]Easy/Moderate/Hard[/b][/color]
TEXT...
[url=http://scratch.mit.edu/forums/viewtopic.php?pid=991961#p991961]^ Home[/url]

Last edited by Hardmath123 (2011-11-11 10:45:43)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#37 2011-11-11 11:22:11

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

Thanks, Hardmath123, that's added  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#38 2011-11-11 12:05:03

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

^ Home
PHP variables
Difficulty: Easy

Variables are what PHP is all about. They allow you to count, store and display information and generally they are the very underpinning of the language so learning to use them is a good idea.

Things you should know
     - PHP can only be used in a .php file.
     - Within that file, all PHP mich be written within <?php and ?> tags or they won't
       work.
     - A variable is a "space" that can hold a changeable value. Like a little box for
       words, lists and numbers.

Syntax
PHP variables don't have many rules to work. Variables have to be created and set to something before they can be used, and they always start with a $ symbol.

Code:

<?php
$treeCounter = 0;
?>

In this example there are three things to note. Firstly, the variable has a descriptive name which indicates what it is doing. It's very good practice to do this or you'll forget what your code is doing and other people will struggle to help you if you get stuck. Secondly, notice that the variable starts with a lowercase and the second word is started with a capital rather than a space. This is called camel case. Spaces can not be used in a variable name so eitherCamelCase or_underscores are used though camelCase is considered standard practice.

Thirdly, notice that the variable is instantly set to something. In this case 0. 0 is a number and can just be typed but if you wanted a word you would enclose it in speech marks to create a string. The "=" symbol sets the variable and a semi-colon ( wink  ends the line. These are both necessary.

Code:

<?php
$treeCounter = 0;
$treeCounter ++;
?>

In this second example, the variable treeCounter is once again created and set to 0. On the second line you can see a piece of code which increments (increases the value by 1) the variable. This would do the same thing as doing $treeCounter = $treeCounter + 1;. This will leave the value of treeCounter as 1 by the end of the script.

GET variables

Variables can actually be placed into the URL of a PHP page. This lets you send someone a link with information in it that the page can take. For example, your friend Josh wants to see the cool page you've been working on so you send him a link like this one:

Code:

http://www.mywebsite.com/greeting.php?name=josh&time=morning

The main part here to concentrate on is the "?name=josh&time=morning" part. the "?" after the normal page URL lets the page know that there are potentially variables in the URL name. "name" and "time" are variables as they are on the left hand side of the = symbol whilst "josh" and morning are on the right, making them values. The "&" symbol lets you seperate the variables in the URL, don't forget to add it between variables if you have more than one!

So you've sent Josh this link and when he follows it, he will be potentially amazed that, without entering anything on the page, the site nevertheless seems to know his name and the time because you've used a script like this one:

Code:

<?php
echo "<p>Hello, " . $_GET['name'] . "! Isn't it a lovely " . $_GET['time'] . "?</p>";
?>

This script pulls the name and time out of the URL and sends it back to him in a sentance. Josh would see the text "Hello, Josh! Isn't it a lovely morning?" on his screen.

A few things to explain there, firstly the echo command. Anything between an echo command and the next ; will be printed onto the page for people to see. Anything in speech marks will be sent as you see it, including HTML like the <p> tags. anything not in speech marks is treated as a variable, and the contents of the variable is sent instead.

Notice that several things are being sent - strings and variables and that they are seperated by periods (.). Periods allow you to join several things together to make one whole thing.

the $GET[] symbol tells the script that this variable is coming from the URL and to look for it there. The name of the variable goes in the square brackets in singe speech marks (such as 'name') and the value of the variable is read out by the script (such as 'Josh').

^ Home


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#39 2011-11-11 12:47:39

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

Espevoir asks: "What is PHP? I want to learn but don't get it at all!"

PHP stands for "PHP: Hypertext Preprocessor" which rather confusingly is a recursive acronym...

Anyway. PHP is a web-oriented lightweight scripting language that web servers can use to (among other things) change the contents of a webpage so that different users can see the same page differently based upon time, place, details, IP and a host of other factors.

The main strength of PHP is its variables - which allow you to store and move data around the page as well as across all the pages of a website) - and it's ability to connect to databases where the data it collects can be stored and recalled using SQL.

PHP code is hidden from the viewer so unlike HTML or Javascript, passwords and other sensitive information can be written through it or handled by it since there is no way for the end user to see what's happening. It is carried out by the server rather than the browser which means your browser never sees the code either, only the end result.

PHP can appear in any file that ends in .php and all PHP code must be placed within <?php and ?> tags to work. .php files also take javascript, HTML etc.

To get started with PHP you will need a webhost, even a free one like 000webhost will do, as you need a server to actually run your PHP scripts. To get started with PHP I personally recommend w3schools which is a great place to start learning PHP with easy-to-understand tutorials. It says you need to know Javascript first but it's not necessary as I learnt it after PHP. You should have a basic knowledge of HTML though, as PHP deals with it a lot!

I hope this helps!

Last edited by sparks (2011-11-11 12:52:16)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#40 2011-11-11 14:31:28

gbear605
Scratcher
Registered: 2008-03-06
Posts: 1000+

Re: Web-languages: Help and helper thread

Hey guys.

Ok, so I made a quick little thing for this, here: web.escratch.org.  This is a perfectly legal site, because you need a moderator to approve your comment before it is published, and only approved people can post blog posts.  I'll allow a few people to make blogposts (like hardmath, and sparks), but for everyone else, if they want to have their entry published, post it here, and we will add it for you!

Its not quite done yet, but it will be soon.

smile


Yeah, I'm mostly inactive.  I check in once in a while though.  If you want to contact me, I have a contact form at my website, http://escratch.org

Offline

 

#41 2011-11-11 14:37:16

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

This seems really cool, gbear, I was excited when I first saw it, but then I thought: There are tons of web-language discussion sites, the aim of this thread is to give people in AT and easy-to-spot-easy-to-check place to post tutorials and such... I don't know what other people think - I'd like to hear them but it seems that putting it on another site won't be as accessible and then it may as well be any web-discussion site?

I'm sorry if that sounds harsh, if you disagree I'd be more than happy to hear why  smile

Last edited by sparks (2011-11-11 14:37:47)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#42 2011-11-11 14:40:39

gbear605
Scratcher
Registered: 2008-03-06
Posts: 1000+

Re: Web-languages: Help and helper thread

sparks wrote:

This seems really cool, gbear, I was excited when I first saw it, but then I thought: There are tons of web-language discussion sites, the aim of this thread is to give people in AT and easy-to-spot-easy-to-check place to post tutorials and such... I don't know what other people think - I'd like to hear them but it seems that putting it on another site won't be as accessible and then it may as well be any web-discussion site?

I'm sorry if that sounds harsh, if you disagree I'd be more than happy to hear why  smile

I do agree that is is sorta a web-discussion site, but, part of the reason is for the organization.  Part is because I think it would be a good way for people to look quickly at recent tutorials and see whats new.  And hey, I think it looks cooler  tongue


Yeah, I'm mostly inactive.  I check in once in a while though.  If you want to contact me, I have a contact form at my website, http://escratch.org

Offline

 

#43 2011-11-11 17:09:27

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

Good point. What do other people think?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#44 2011-11-11 20:25:41

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Web-languages: Help and helper thread

sparks wrote:

Good point. What do other people think?

I think it is easier to ask questions here than to go to another website. I don't think it's necessary and I prefer the plainer layout here in the Scratch Forums rather than something that isn't freely available to ask questions on.

Though it may become useful in the future.  smile

Last edited by Magnie (2011-11-11 20:26:54)

Offline

 

#45 2011-11-11 20:28:27

gbear605
Scratcher
Registered: 2008-03-06
Posts: 1000+

Re: Web-languages: Help and helper thread

Magnie wrote:

sparks wrote:

Good point. What do other people think?

I think it is easier to ask questions here than to go to another website. I don't think it's necessary and I prefer the plainer layout here in the Scratch Forums rather than something that isn't freely available to ask questions on.

Though it may become useful in the future.  smile

My thinking was that this thread would be useful for questions/help, and the website would have tutorials, and stuff like that.


Yeah, I'm mostly inactive.  I check in once in a while though.  If you want to contact me, I have a contact form at my website, http://escratch.org

Offline

 

#46 2011-11-11 22:47:15

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Web-languages: Help and helper thread

gbear605 wrote:

Magnie wrote:

sparks wrote:

Good point. What do other people think?

I think it is easier to ask questions here than to go to another website. I don't think it's necessary and I prefer the plainer layout here in the Scratch Forums rather than something that isn't freely available to ask questions on.

Though it may become useful in the future.  smile

My thinking was that this thread would be useful for questions/help, and the website would have tutorials, and stuff like that.

That works. Would be especially helpful for those big tutorials.

Offline

 

#47 2011-11-12 02:35:53

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

I'd prefer to use this thread only. A website makes sharing your tutorials look harder; here you just post it on. Also, a website completely breaks the link with Scratch. Oh, and you can add a NEW! tag next to new ones.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#48 2011-11-12 04:02:24

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web-languages: Help and helper thread

I have a code:

Code:

<?php
include "demo.html";
include "connect.php";
session_start();
if (!($_GET['id'] == "")) {
$idr = $_GET['id'];
$result3 = mysql_query("SELECT * FROM games WHERE id = '$idr'", $link);
$mysql_nums = mysql_num_rows("SELECT * FROM games WHERE id = '$idr'", $link);
if ($mysql_nums < 1) {
echo "<p>Game doesn't exist.</p>";
} else {
while($rowr=mysql_fetch_array($result3)){
$url2 = $rowr['url'];
$name2 = $rowr['name'];
$by2 = $rowr['by'];
$id2 = $rowr['id'];
echo "<p><b><u>$name2</u>:</b><br /><applet id=\"ProjectApplet\" style=\"display:block\" code=\"ScratchApplet\" codebase=\"http://plaxon.comyr.com/games\" archive=\"ScratchApplet.jar\" height=\"387\" width=\"482\">
<param name=\"project\" value=\"$url2\"></applet><br />";
}
echo "</p>";
}
} else {
$num_result = mysql_num_rows("SELECT * FROM games", $link);
if ($num_result == "0") {
echo "<p>No games yet!</p>";
} else {
$result = mysql_query("SELECT * FROM games", $link);
$num_rows = mysql_num_rows($result);
echo "<p>";
while($row=mysql_fetch_array($result)){
$url = $row['url'];
$name = $row['name'];
$by = $row['by'];
$id = $row['id'];
echo "<p><a href=\"game.php?id=$id\">$name</a> by $by<br />";
}
echo "</p>";
}
}
?>

and I keep getting:
Warning: Wrong parameter count for mysql_num_rows() in /home/a5292800/public_html/game.php on line 23
and when i click the game link
Warning: Wrong parameter count for mysql_num_rows() in /home/a5292800/public_html/game.php on line 8

see it at http://www.plaxon.comyr.com/game.php


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#49 2011-11-12 08:43:27

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Web-languages: Help and helper thread

Line 23: $num_result = mysql_num_rows("SELECT * FROM games", $link);

The SQL needs to be a query first:

$num_result = mysql_num_rows(mysql_query("SELECT * FROM games", $link));

That should work. The same goes for Line 8, you need to add the mysql_query.

Last edited by Magnie (2011-11-12 08:44:27)

Offline

 

#50 2011-11-12 09:39:54

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web-languages: Help and helper thread

Magnie wrote:

Line 23: $num_result = mysql_num_rows("SELECT * FROM games", $link);

The SQL needs to be a query first:

$num_result = mysql_num_rows(mysql_query("SELECT * FROM games", $link));

That should work. The same goes for Line 8, you need to add the mysql_query.

Thanks  smile  it works now! You do know a lot about php  wink


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

Board footer