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)
Offline
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
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)
Offline
Ok!
Edit:
If I get stuck Ill ask for help here!
Last edited by johnnydean1 (2011-04-10 11:47:26)
Offline
Ok, BTW I dont want to use 000webhost or pay to host a website so any others you can reccomend?
Offline
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)
Offline
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.
Offline
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!
Offline
Well heres my code:
xxx is stuff I dont want you to see
<?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!
Offline
Panther Blocks:
get var $String$
Type: r
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].
^ t7Set var $String$ to $String$
Type -
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.
^ t5Last edited by johnnydean1 (2011-04-11 05:15:13)
Offline
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
Unless you make the registration free
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!
Last edited by sparks (2011-04-10 16:51:47)
Offline
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.
Offline
Added instructions and a way of seeing all data.
See here
Offline
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.
My site Offline
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.
Offline
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
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
Last edited by sparks (2011-04-11 06:31:59)
Offline
Thanks for the spelling help (I thought it was wrong). Do you like it though?
Offline
I love it! I've made blocks that connect, set and read variables
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?
Offline
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$
self addVariable: 'onlineUsername'. self setVar: 'onlineUsername' to: t1.
create online variable $String$
|t2| t2_ self reportVar: 'onlineUsername'. self readFromUrl: 'http://scratchlive.xtreemhost.com/set.php?user=', t2, '_', t1, '&pass=1'
set online variable $String$ to $String$
|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$
|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)
Offline
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.
Offline
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.
Offline
Claw Image
Select PHP and show PHP blocks.
Last edited by johnnydean1 (2011-04-11 07:21:57)
Offline
sparks wrote:
Did you see post #21? I'm in the UK too
![]()
I saw
Offline