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

#1 2012-02-17 15:02:42

minie87
New Scratcher
Registered: 2012-02-17
Posts: 8

Passing info from Scratch project to database

Hello everyone,

I am a new member here and is a beginner with Scratch.
I would like to use my scratch project in a personal website.
Is it possible for the scores from the scratch game to be passed and saved in a database?
I would like to use the game's score as the level breaker to enter the next level.

Would really appreciate help from any Scratch members. thank you very much!

Regards,
minie

Offline

 

#2 2012-02-17 15:07:54

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

Re: Passing info from Scratch project to database

At the moment, it is really complicated.

ZeroLuck created a Java Player that can connect to servers/other Scratch projects here.

Though currently, you can't directly manipulate a database. You need a server running that the project connects to, and then that server connects to the database.

Problem is, you need the server to parse the information sent from the Scratch project. So you won't be able to do this with a simple site. You need a server/VPS to be able to do something like that.

Offline

 

#3 2012-02-17 15:24:51

minie87
New Scratcher
Registered: 2012-02-17
Posts: 8

Re: Passing info from Scratch project to database

thank you for the instant reply Magnie!

I'm still in confusion, sorry... i am actually creating a website. and right now i am testing it using the xampp (Apache, mysql). so what should i do next once after embedding the .sb project into the webpage?

please do assist me.. thank you!

Offline

 

#4 2012-02-17 15:48:01

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

Re: Passing info from Scratch project to database

You need to code a server that the Scratch Project connects to.

There are a couple ways you can go about making a score board. First one, is you can have the server connect to the MySQL database and add the scores from there. Or second, you can have the server save the scores onto a file, which will probably be simpler and more secure than connecting to a MySQL database.

Offline

 

#5 2012-02-17 17:05:59

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: Passing info from Scratch project to database

Or (when TheSuccessor is done with my Panther Java Player) use GET requests via Panther's content of URL block.


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#6 2012-02-18 10:56:20

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: Passing info from Scratch project to database

Magnie wrote:

At the moment, it is really complicated.

ZeroLuck created a Java Player that can connect to servers/other Scratch projects here.

Though currently, you can't directly manipulate a database. You need a server running that the project connects to, and then that server connects to the database.

Problem is, you need the server to parse the information sent from the Scratch project. So you won't be able to do this with a simple site. You need a server/VPS to be able to do something like that.

I Love that mod ^^ lovely java  big_smile   big_smile   


[sob sob .. scratch team decided to degrade to ugly and Evil flash  sad   sad  ]
oh by the way saving to a file wont be atomically updating if two updates come at same time, the code will have to be complexed to handle such events and hence i suggest using mySql its easy though the harder part is parser  tongue 


@person here is how you should do stuff while connecting java app to server

[MYSQL DATABASE] ------- Via PHP or Server Side Script ---> [JavaApp]

Now let me explain how to do this nicely;

1. make a format and parser / encoder for it
  we will use our own flavoured markup here .. i call it darkML ..  wink 
       variable:value;variable2:value;variable3:value;
2. Now once your format is decided lets write an encoder for it via php

Code:

  <?php 
   $user = 'root'; // Change this to username
   $password = ''; // Put ur pass here my home db dosnt has any password
   $HOST = 'localhost';
   $con = mysql_connect($HOST,$user,$password) or die('Could Not Connect..'); 
   mysql_select_db('scores',$con);
   $result = mysql_query('Select * from highscores"); /* this will fetch all values for us */
   while( $score = mysql_fetch_assoc($result)){
      echo 'Name:'.$score['Name'].';';
      echo 'Score:'.$score['score'].';';
      echo 'param':$score['param'].';';
      echo '&';
   }
  ?>

for the sake of simplicity i have made it simple. magnie might wanna lend me a hand and expand it

the output of that file called will be like
Name:Dark;Score:3;param:xz;&Name:Magnie;Score:199;param:omg;&

now we have to store it in a variable in scratch :-)

say we will choose the variable name to be HighScoreRaw;
now parsing HighScoreRaw is like reverse engineering how it was made so here is how you do it

since each user is differentiated from the other by an &;
and variable name and values are paired with ':' where a ';'  differentiates among two   variables ...

I wrote a parser for you in scratch to explain it
http://scratch.mit.edu/projects/fanofcena/2340838 feel free to morph it  wink
and to use variables just use the [item a === 'varname'] operation  smile   


By the way here is how the parser works

converts the string to an array
now loops till it encounters a : and pushes it to user name
then loops to ; and pushes the value to the value array

[ofcousre there can be better methods to write this . but i wrote it this way for the sake of simplicity  optionally he can use the letter in word block in scratch to do the parsing very compactly ]

But well to do reverse process you have to do the total reverse. :-) hope that helps ^^

Last edited by fanofcena (2012-02-18 23:32:17)


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#7 2012-02-20 02:28:38

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: Passing info from Scratch project to database

Oi was my post even use full >??

if not

100x facepalm


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

Board footer