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

#1 2011-04-10 11:40:38

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Scratch Live

Up-to-date: Claw

JD1 wrote:

@Sparks
Do you know anyway of linking Scratch (or a mod) to a server (maybe through PHP) for a online mesh?

Sparks wrote:

Any mod with a url reading capabilities can use a website as a "server" using php and MySQL. The php can be placed in a block request like so:

contents of file at URL:(http://examplewebsite.com/playerstatus.php?username=jd1&password=pass&status=feeling%20bored!)

this would send the information of username, password and status to the php page when it reads it. Panther appears to read back the html but it triggers the php code at the same time. This way MySQL can now add that status to a MySQL table in the status space next to your username where other people can read it through something along the lines of /statuses.php?username=jd1. A message can even be sent back to Panther through html saying if the update was sucessful or not!

JD1 wrote:

Can you code that?

Move Conversation about this here. Keep on topic!!

Last edited by johnnydean1 (2011-08-08 05:18:13)


You can now reach me on Twitter @johnnydean1_

Offline

 

#2 2011-04-10 11:45:22

YourLocalBlockLib
Scratcher
Registered: 2011-03-10
Posts: 100+

Re: Scratch Live

I could... I'm really working on my own site at the moment, but If you haven't worked out how to do it by the time I've finished my first full-length game (which has online scoring) I'll trust you with the source of the Panther project so you can take a look! It's more or less the above method though  tongue  Go to W3Schools, they have loads of tutorials on php and MySQL. Weebly does not support php but 000webhost or hosting24 does!

~~Sparks

Last edited by YourLocalBlockLib (2011-04-10 11:45:38)


http://dl.dropbox.com/u/6273449/BlockLibraryTitle.png

Offline

 

#3 2011-04-10 11:47:04

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Ok!

Edit:
If I get stuck Ill ask for help here!

Last edited by johnnydean1 (2011-04-10 11:47:26)


You can now reach me on Twitter @johnnydean1_

Offline

 

#4 2011-04-10 11:52:50

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

Re: Scratch Live

Alright  smile  I'll help out when I have the time and try and answer your questions!


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

Offline

 

#5 2011-04-10 11:53:46

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Ok, BTW I dont want to use 000webhost or pay to host a website so any others you can reccomend?


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2011-04-10 12:01:48

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

Re: Scratch Live

I use hosting24 as my paid webhost and I have no complaints. Unlimited everything with included phpmyadmin, SQL database helper, php, javascript etc for about £3 a month!


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

Offline

 

#7 2011-04-10 12:11:30

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

sparks wrote:

I use hosting24 as my paid webhost and I have no complaints. Unlimited everything with included phpmyadmin, SQL database helper, php, javascript etc for about £3 a month!

I found xtreemhost, they seem to do the job.

Last edited by johnnydean1 (2011-05-23 03:04:53)


You can now reach me on Twitter @johnnydean1_

Offline

 

#8 2011-04-10 15:26:39

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Done it and kept a back-up of the code. Snazzy. I will include a new block here to use it.

All the best JD1.


You can now reach me on Twitter @johnnydean1_

Offline

 

#9 2011-04-10 16:03:27

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

Re: Scratch Live

You mean a server that all games can use? How do you plan to do that? Wouldn't you need to have a table per project that used it? Or even a database per project!

But congrats on getting it to work, I look forward to seeing the block!


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

Offline

 

#10 2011-04-10 16:08:55

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Well heres my code:
xxx is stuff I dont want you to see

Code:

<?php 

$SQLhost     = "xxx";
$SQLuser     = "xxx";
$SQLpass     = "xxx";
$SQLdatabase = "xxx";
$SQLtable    = "xxx";

$con = mysql_connect($SQLhost,$SQLuser,$SQLpass);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
echo "Database Connected";
echo "<br />";
$user  = $_GET["user"];
$pass  = $_GET["pass"]; 
$value = $_GET["value"];

echo $user;
echo "<br />";
echo $pass;
echo "<br />";
echo $value;
echo "<br />";
                        if ($pass == 1)
                                {


$val = strlen($value);
if ($val > 0)
{
    echo "Acting on request";
    $act = "set";
}
else
{
    echo "Getting request";
    $act = "get";
    }
echo "<br />";


//**************************
//******DATABASE STUFF******
//**************************

mysql_select_db($SQLdatabase, $con);

            if(1==0)
                {

                    $sql = "CREATE TABLE" . $SQLtable. "
                    (
                    Username varchar(20),
                    Value varchar(20),
                    )";
                    mysql_query($sql,$con);
                    echo "<br />";
                    echo "Table made";
                    echo "<br />";
            
                }


    $you = "
SELECT * 
FROM Users";
$you4 = $you;

    
          $result = mysql_query($you4)
or die(mysql_error());
$n = 0;
$get = "";
$x = 0;
while($row = mysql_fetch_array($result))
  {
$x = $x + 1;
    $you = $row['Username'];
  if ($you == $user)
{
$n = $x;
if ($act == "get")
{
$get = $row['Value'];
}

}
 }



if ($n==0)
{
$you = "INSERT INTO ";
$you2 = $SQLtable;
$you3 = " (Username, Value)";
$you = $you . $you2 .$you3;
$you2 = ",";
$you3 = ")";
$you4 = "'";
$you5 = " VALUES (";
$query = $you . $you5 . $you4. $user . $you4 . $you2 . $you4. $value. $you4. $you3;
mysql_query($query);
}




                                echo "<br />";
                                echo "\n";




if ($act == "get")
{
echo $get;

}
if ($act == "set")
{


$you = "UPDATE ";
$you2 = $SQLtable;
$you3 = " SET Value = '";
$you = $you . $you2 .$you3 . $value;
$you2 = "' WHERE Username = '";
$you3 = $user;
$you4 = "'";
$query = $you . $you2 . $you3 . $you4; 
mysql_query($query);
echo "Updated";
}
                                }

mysql_close($con);
?>

My first real go at PHP!


You can now reach me on Twitter @johnnydean1_

Offline

 

#11 2011-04-10 16:12:32

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Panther Blocks:
get var $String$
Type: r
Code:

Code:

    | t2 t3 t4 t5 t6 t7 |
    t2 _ 'http://scratchlive.xtreemhost.com/set.php?'.
    t2 _ t2 asString.
    t3 _ t2 , 'user=' , t1 , '&pass=1'.
    t4 _ self readLine: 4 FromUrl: t3.
    t4 = '<html>' ifTrue: [t4 _ ''].
    t5 _ 0.
    t7 _ ''.
    t4 size
        timesRepeat: 
            [t5 _ t5 + 1.
            t6 _ self letter: t5 of: t4.
            t6 = '%' ifTrue: [t6 _ ' '].
            t7 _ t7 , t6].
    ^ t7

Set var $String$ to $String$
Type -
Code:

Code:

 
    | t3 t4 t5 t6 t7 t8 |
    t6 _ 0.
    t8 _ ''.
    t2 size
        timesRepeat: 
            [t6 _ t6 + 1.
            t7 _ self letter: t6 of: t2.
            t7 = ' ' ifTrue: [t7 _ '%'].
            t8 _ t8 , t7].
    t3 _ 'http://scratchlive.xtreemhost.com/set.php?'.
    t3 _ t3 asString.
    t4 _ t3 , 'user=' , t1 , '&pass=1&value=' , t8.
    t5 _ self readLine: 4 FromUrl: t4.
    ^ t5

Last edited by johnnydean1 (2011-04-11 05:15:13)


You can now reach me on Twitter @johnnydean1_

Offline

 

#12 2011-04-10 16:47:53

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

Re: Scratch Live

Is this a database anyone can use? How do I create a variable with a block? It looks great, but I don't want to put something in the library where you have to register to use the block or something  tongue  Unless you make the registration free  big_smile

Oh, It is both illigal and unsafe to store passwords in a SQL table without encrypting them! Look into MD5 for storing and reading passwords from the table!

MD5($_POST['pass'])

Then add it as MD5 to the table.

When comparing the password sent by the user to the MD5 ecrypted table entry, convert the given password to MD5 and then compare that to the stored one!  smile

Last edited by sparks (2011-04-10 16:51:47)


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

Offline

 

#13 2011-04-11 03:06:26

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

The pass is just 0 or 1. 0 doesn't do anything, 1 performs a action.

The database is free on the hosting site I am on. To make a var declare it a value and it will be made.


You can now reach me on Twitter @johnnydean1_

Offline

 

#14 2011-04-11 05:10:27

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Added instructions and a way of seeing all data.
See here


You can now reach me on Twitter @johnnydean1_

Offline

 

#15 2011-04-11 05:49:49

what-the
Scratcher
Registered: 2009-10-04
Posts: 1000+

Re: Scratch Live

johnnydean1 wrote:

Sparks wrote:

Any mod with a url reading capabilities can use a website as a "server" using php and MySQL. The php can be placed in a block request like so:

contents of file at URL:(http://examplewebsite.com/playerstatus.php?username=jd1&password=pass&status=feeling%20bored!)

this would send the information of username, password and status to the php page when it reads it. Panther appears to read back the html but it triggers the php code at the same time. This way MySQL can now add that status to a MySQL table in the status space next to your username where other people can read it through something along the lines of /statuses.php?username=jd1. A message can even be sent back to Panther through html saying if the update was sucessful or not!

Yes. I know this. ME and someone else developed this many many months ago.


http://imageshack.us/m/64/9034/ddfss.pngMy site
Find someone post count. Click posts under username. Find number of pages. Times that by 40 for min and 60 for max and you have a rough estimate of post count.

Offline

 

#16 2011-04-11 06:13:33

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

what-the wrote:

johnnydean1 wrote:

Sparks wrote:

Any mod with a url reading capabilities can use a website as a "server" using php and MySQL. The php can be placed in a block request like so:

contents of file at URL:(http://examplewebsite.com/playerstatus.php?username=jd1&password=pass&status=feeling%20bored!)

this would send the information of username, password and status to the php page when it reads it. Panther appears to read back the html but it triggers the php code at the same time. This way MySQL can now add that status to a MySQL table in the status space next to your username where other people can read it through something along the lines of /statuses.php?username=jd1. A message can even be sent back to Panther through html saying if the update was sucessful or not!

Yes. I know this. ME and someone else developed this many many months ago.

So sorry old chap but me and Successor got there first over 5 months ago.


You can now reach me on Twitter @johnnydean1_

Offline

 

#17 2011-04-11 06:30:11

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

Re: Scratch Live

I think a nice option for this would be that if your site subscription comes with unlimited SQL tables, to offer a table to each scratcher who wants one. This would allow more than one person to use a variable called score or health or some other name that is likely to be used in multiple areas  smile  Of course, you could sort of follow the rule that everyone makes variables like so:

sparks_score
sparks_health

or game names:
bubblePopper_score
bubblePopper_health

In which case a "server variable $String$ already exists?" block might be a good idea? Otherwise people would accidentally overwrite someone else's data.

EDIT: p.s. "coding" and "making" do not have "e"'s in them, you misspelt it on the scratchlive site  smile

Last edited by sparks (2011-04-11 06:31:59)


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

Offline

 

#18 2011-04-11 06:34:50

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Thanks for the spelling help (I thought it was wrong). Do you like it though?


You can now reach me on Twitter @johnnydean1_

Offline

 

#19 2011-04-11 06:46:28

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

Re: Scratch Live

I love it! I've made blocks that connect, set and read variables  big_smile  I have an idea that I'm working on to do with multiple variable names being easier to use too! I'll tell you about it if I can get it working. Is there a way to create global variables that are invisible in the variables menu but can still be read using the self reportVar: ( ) smalltalk command?


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

Offline

 

#20 2011-04-11 07:05:57

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

Re: Scratch Live

Are you on holiday at the moment? I Have a bit more free time right now so I reckon we could take this a long way together! I'm thinking that if we include a "set server username to $String$" block we can create and set a global variable with that block using code something along these lines:

set online username to $String$

Code:

self addVariable: 'onlineUsername'.
self setVar: 'onlineUsername' to: t1.

create online variable $String$

Code:

|t2|
t2_ self reportVar: 'onlineUsername'.
self readFromUrl: 'http://scratchlive.xtreemhost.com/set.php?user=',  t2, '_',  t1, '&pass=1'

set online variable $String$ to $String$

Code:

|t3|
t3_ self reportVar: 'onlineUsername'.
self readFromUrl: 'http://scratchlive.xtreemhost.com/set.php?user=', t3, '_',  t1, '&pass=1&value=', t2

value of mesh variable $String$

Code:

|t2|
t2_ self reportVar: 'onlineUsername'.
^ self readLine: 4  FromUrl: 'http://scratchlive.xtreemhost.com/set.php?user=', t2, '_',  t1, '&pass=1'

This way, the online username and a _ is added before each variable, giving that project a hopefully unique set of variables!

A bit of code tweaking to that should allow us to pop up a dialogue if the user name has not been set to anything yet. Those blocks all worked very nicely for me! The only thing I'm not happy with with those is that the variable "onlineUsername" is global and avaliable in the variable dropdown list. What we really need is a global smalltalk variable that the blocks can read but remain undetected by panther itself without having to create a new method in the browser for them. Panther custom blocks do not allow you to make new dropdowns so unfortunately there isn't a way to have a dropdown of existing  online variables without adding each online variable as a scratch variable too!

Last edited by sparks (2011-04-11 07:09:58)


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

Offline

 

#21 2011-04-11 07:13:24

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

Re: Scratch Live

something we could think about doing is once we're happy with the ins and outs of the blocks and server side of the project, we could provide a version of Scratch that is the same as the normal version but it also includes these blocks and contact the many mods and see if they would be interested in releasing a second version of their current release containing these blocks. That way we could try and get all mods connected to the one mesh system! This still needs some work, but in the end connecting all the mods to this would be a great idea, I think.


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

Offline

 

#22 2011-04-11 07:13:48

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Yes I am on Holiday at the moment. (Im in the UK BTW). I will post a up to date image of Claw here soon. Claw is where the blocks were designed for so it should work better. Have a go at modding it with the blocks.


You can now reach me on Twitter @johnnydean1_

Offline

 

#23 2011-04-11 07:19:28

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

Claw Image
Select PHP and show PHP blocks.

Last edited by johnnydean1 (2011-04-11 07:21:57)


You can now reach me on Twitter @johnnydean1_

Offline

 

#24 2011-04-11 07:21:54

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

Re: Scratch Live

Did you see post #21? I'm in the UK too  smile


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

Offline

 

#25 2011-04-11 07:22:42

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Live

sparks wrote:

Did you see post #21? I'm in the UK too  smile

I saw


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer