My examples

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  <12345>
Author
309 Rep
Post Options Post Options   Quote sled Quote  Post ReplyReply Direct Link To This Post Posted: 18 Jan 2012 at 7:19pm
OK i got this working, but where and how do i have to put my variables for user:
I want this:
When level is finished -> display text field where user could enter their name -> and when hitting enter the hiscore board is displayed with actual score and name of that user.
Now i've got only this and don't know how to replace NEWENTRY and 1337 for variables:


"post.php?name=NEWENTRY&score=1337"

"readscores.php?num_scores=10"
Back to Top
11,720 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 18 Jan 2012 at 11:53pm
you should add a Text box on your layout where the player will enter his name, and on click on the validation button, you will send an Ajax request that will look like :
-> Ajax: Request "http://yourURL/post.php?name="&Textbox.text&"&score="&score (tag "sendScore")
Back to Top
309 Rep
Post Options Post Options   Quote sled Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2012 at 2:08pm
Thanks Yann, with your fantastic help I was able to get it right, but now I have another question.
I want to do this hiscore thing with spritefont plugin, but scores are displayed inline(player1,30,player2,50...and so on) with that plugin and i don't have to say that it looks bad.
How to make them display in block like in normal font.
Back to Top
11,720 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2012 at 2:17pm
haha inline, inblock, you talk like a css guy.
Well, I'm not sure how your datas are returned by your php script but you should either return them with "\n" at the end of each line, or with a special character.
For example if you use "|" you can do
+Ajax: On "hiscore" completed
+for "" from 0 to tokencount(Ajax.LastData,"|")
    -> spritefont: append text tokenat(Ajax.LastData,loopindex,"|")
    -> spritefont: append text newline


Edited by Yann - 20 Jan 2012 at 2:17pm
Back to Top
309 Rep
Post Options Post Options   Quote sled Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2012 at 5:37pm
Yes I know that inline and block was in css, and i thought that it describes the situation quite well:D

I must doing something wrong. When i put your code in event sheet everything is good, but no results in game, hiscores still displays in one line and not in a block. This spritefont is a plugin i have found in this forum. It's a sprite, so i think i can't append text to it :(
Anyway here are my screenshots, I hope they are allowed here.

First is this Spritefont object events(they are not mine, they were in example of usage)


second are the request to php



and the third is your Ajax condition, on my events:


I checked the post.php file, and it has this "\n" at the end



Edited by sled - 20 Jan 2012 at 5:40pm
Back to Top
11,720 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2012 at 7:23pm
You are obviously not using the spritefont plugin
Back to Top
4,219 Rep
Post Options Post Options   Quote Ize Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2012 at 9:14pm
hey @Yann thanks for cleaning up the gesture.capx a bit :)
Back to Top
5,635 Rep
Post Options Post Options   Quote smitchell Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2012 at 9:16pm
@ize, Whilst your here What do i need to add to the PHP to get the rank of the player? I know it orders them but if i wanted to display the rank?

thanks.
In memory of flash :'(
Back to Top
4,219 Rep
Post Options Post Options   Quote Ize Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2012 at 9:18pm
to be honest i never got that far :)

you'd have to write your own function to sort the array either in php or in c2
Back to Top
5,635 Rep
Post Options Post Options   Quote smitchell Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2012 at 9:27pm
ahhh ok i'll have a look online
In memory of flash :'(
Back to Top
 Post Reply Post Reply Page  <12345>

Forum Jump Forum Permissions View Drop Down