Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Possible to store ranking lists on server? — Gideros Forum

Possible to store ranking lists on server?

HolonistHolonist Member
edited July 2015 in General questions
Hi,

So far I haven't seen much content for making Gideros apps go online.
I've seen a tutorial with LuaSocket, but wasn't able to follow it through, and I think it was only for local networks, so pretty pointless for something like online rank lists.

I've recently built a lot with php at work, so I know how to do stuff with a MySQL database. Unfortunately, SQL is not supported natively by Lua or Gideros (except SQLite, which is local?).

On the Google, I got a hint to look at LuaSQL-MySQL, but the instructions on how to install it are too damn hard. It's like they force you to use Linux and it seems you even have to compile things at some point. Having to follow 20+ steps that involve manually changing system files kind of ruins the point of using a "1-click-and-you're-set" solution like Gideros.

I'm not really here to rant. Can someone give me directions on how to possibly make online rank lists happen with Gideros? (idiotproof please). Also I think, if this is possible, online stored user saves are not that far away.

Greetings

Comments

  • HolonistHolonist Member
    edited July 2015
    Maybe display a webpage inside the app and let html/php take over? But how would I pass the values from the lua app to the web page? (ignoring that I'm afraid that displaying web pages in Gideros will be far from easy, too...)
  • talistalis Guru
    edited July 2015
    If you do not want to use a third party leaderboard service with a rest api than you have one alternative.
    Take the values by urlloader from a php web site via webservice. (in json format will be better)
    And then parse json in your program.
  • ar2rsawseenar2rsawseen Maintainer
    Basically yes, create your own rest api using mysql and php on server and use url loader to load the data and submit to your server

    Likes: Holonist

    +1 -1 (+1 / -0 )Share on Facebook
  • HolonistHolonist Member
    edited July 2015
    Could you tell me how to send variables with UrlLoader?

    I have two variables, username and password. The containing element is a Gideros object called 'form' (just so you know what "self" is referring to)
    self.formName = "user"
    self.formPassword = "1234"
     
    local contents = {
    	"name" = self.formName,
    	"password" = self.formPassword,
    }
    contents = json.encode(contents)
     
    local headers = ???
    local send = ???
     
    self.loader = UrlLoader.new("<a href="http://secret.com/gid/register.php"" rel="nofollow">http://secret.com/gid/register.php"</a>, UrlLoader.POST, headers, send)
    what do i put in headers and send? I checked http://docs.giderosmobile.com/reference/gideros/UrlLoader#UrlLoader but I don't want to send a picture.
  • ar2rsawseenar2rsawseen Maintainer
    edited July 2015
    Hello,
    from:
    http://docs.giderosmobile.com/reference/gideros/UrlLoader/new#UrlLoader.new

    you should do something like:
    UrlLoader.new("<a href="http://secret.com/gid/register.php"" rel="nofollow">http://secret.com/gid/register.php"</a>, UrlLoader.POST,
     {}, "username="..self.username.."&password="..self.password)
    that is if you expect $_POST["username"] and $_POST["password"] on server
  • This is how i had sent data
    		 local data = {
    		["mode"] = "postUserScore",
    		["username"] = dataSaver.loadValue("username"),
    		["score"] = dataSaver.loadValue("myScore")
    		}
    --Json Call
    		local body = Json.Encode (data)
    		local url="<a href="http://subdomain.domain.com/core/myProject/admin/webservice.php&quot" rel="nofollow">http://subdomain.domain.com/core/myProject/admin/webservice.php&quot</a>;
    		local loader = UrlLoader.new(url,UrlLoader.POST,body)
    		loader:addEventListener(Event.COMPLETE, self.onComplete,loader)
    		loader:addEventListener(Event.ERROR, self.onError,loader)
    		loader:addEventListener(Event.PROGRESS, self.onProgress,loader)
  • HolonistHolonist Member
    edited July 2015
    I'm going to look into your mobile backend.

    But for now, I'm getting
    RegisterForm.lua:45: unfinished string near '"<a href="http://svr05/gid/register.php" rel="nofollow">http://svr05/gid/register.php</a> &quot ;'
    --inserted spaces around quot, to prevent html showing it as &quot;
    (realized i dont have to hide the url from you)

    Why don't you get this error, where you don't close the url string?
  • ar2rsawseenar2rsawseen Maintainer
    @Holonist sorry, it is not me, it is forum markup ruining it
    your url should be in "http://svr05/gid/register.php"
    no " stuff needed ;)
  • HolonistHolonist Member
    edited July 2015
    okay, that really confused me because it also happened in hgvyas123's post :D

    It worked with your example, but I'm not yet satisfied with the "style".
    When I try hgvyas123's solution, my $_POST stays completely empty...
    local content = {
    	["name"] = self.name.value,
    	["password"] = self.password.value
    }
     
    content = json.encode(content)
     
    --print(content) shows-> {"name":"somevalue","password":"somevalue"}
    --so it is a common json string		
     
    local loader = UrlLoader.new("<a href="http://svr05/gid/register.php"" rel="nofollow">http://svr05/gid/register.php"</a>, UrlLoader.POST, content)
     
    --returned print_r($_POST) shows->
    Array
    (
    )
     
    --should be, and does work with arturs version:
    Array
    (
        [name] => somevalue
        [password] => somevalue
    )
    I think the json format is also how html form input is normally sent?
    Last sentence is apparently false. Does ajax convert json to a string like val1=a&val2=b&val3=c etc? I thought it just sends it as is

    sorry for changing my attribute names all the time
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Yes json won't be processed as $_POST variables on server, you must use query string format key1=value1&key2=value2, etc

    in ajax, you usually provide not json string, but json object, which internally is converted to query string
  • Ok, thanks. I think I'm good to go now
Sign In or Register to comment.