My examples

Get help using Construct 2

Post » Wed Jan 18, 2012 7:19 pm

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"
B
4
Posts: 17
Reputation: 334

Post » Wed Jan 18, 2012 11:53 pm

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 :
[code]-> Ajax: Request "http://yourURL/post.php?name="&Textbox.text&"&score="&score (tag "sendScore")[/code]
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Jan 20, 2012 2:08 pm

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.
B
4
Posts: 17
Reputation: 334

Post » Fri Jan 20, 2012 2:17 pm

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
[code]+Ajax: On "hiscore" completed
+for "" from 0 to tokencount(Ajax.LastData,"|")
    -> spritefont: append text tokenat(Ajax.LastData,loopindex,"|")
    -> spritefont: append text newline[/code]Yann2012-01-20 14:17:56
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Jan 20, 2012 5:37 pm

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

sled2012-01-20 17:40:32
B
4
Posts: 17
Reputation: 334

Post » Fri Jan 20, 2012 7:23 pm

You are obviously not using the spritefont plugin
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Jan 20, 2012 9:14 pm

hey @Yann thanks for cleaning up the gesture.capx a bit :)
B
33
S
6
G
7
Posts: 338
Reputation: 7,424

Post » Fri Jan 20, 2012 9:16 pm

@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.
B
29
S
12
G
7
Posts: 740
Reputation: 7,839

Post » Fri Jan 20, 2012 9:18 pm

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
B
33
S
6
G
7
Posts: 338
Reputation: 7,424

Post » Fri Jan 20, 2012 9:27 pm

ahhh ok i'll have a look online
B
29
S
12
G
7
Posts: 740
Reputation: 7,839

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: anty21ro, Braus, zenox98 and 2 guests