I've moved to a new host with a new domain just for my game site along with a private ssl cert. So no more weird addresses to use for connecting to my site for the scores database.
If you don't know what I'm talking about, you can read the original thread here:
https://forum.thegamecreators.com/thread/210569
Here's the new website:
Purple Token
I need to update the design, or at least the logo/name (any helpers?). And I think there's a bug with adding new games, it doesn't appear it's uploading images correctly.
Here is an updated snippet using the new address and tested in AGK2. The only things that changed were the following lines:
r = setHTTPHost(http, "purpletoken.com", 1)
sendHTTPRequestASync(http, "update/index.php", vars$)
Full snippet:
#CONSTANT GAME_KEY = "<YOUR_PRIVATE_GAME_KEY>"
playerName$ = "Prince"
score = 3579
Type ScoreUDT
name as string
score as integer
EndType
scoreObject = 0
submitObject = 0
repeat
// Press SPACE key to submit a score
if getRawKeyPressed(32)
score = random(999, 9999)
submitObject = submitScore(playerName$, str(score), GAME_KEY)
endif
// Press ENTER key to retrieve scores
if getRawKeyPressed(13)
scoreObject = getScore(GAME_KEY)
endif
// Score is being submitted, wait for response
if submitObject > 0
res = getSubmissionResponse(submitObject)
if res = 1 then submitObject = 0
endif
// Retrieving scores, wait for response
if scoreObject > 0
scores$ = getScoreResponse(scoreObject)
if scores$ <> ""
scoreObject = 0
count = countStringTokens(scores$, ",")
size = val(getStringToken(scores$, ",", 1))
dim scoreboard[size] as ScoreUDT
j = 1
for i = 2 to count step 2
player$ = getStringToken(scores$, ",", i)
score = val(getStringToken(scores$, ",", i+1))
scoreboard[j].name = player$
scoreboard[j].score = score
inc j
next i
endif
endif
// Score submitted successfully
if res = 1 then print("Submission Successful")
// Display scores
for i = 1 to size
print(scoreboard[i].name+" - "+str(scoreboard[i].score))
next i
sync()
until getRawKeyPressed(27) = 1
end
// Initiate the connection to get list of scores
function getScore(gameKey$)
http = createHTTPConnection()
r = setHTTPHost(http, "purpletoken.com", 1)
vars$ = "gamekey="+gameKey$
sendHTTPRequestASync(http, "update/index.php", vars$)
endfunction http
// Initiate the connection to submit a score
function submitScore(player$, score$, gameKey$)
http = createHTTPConnection()
r = setHTTPHost(http, "purpletoken.com", 1)
vars$ = "player="+player$+"&score="+score$+"&gamekey="+gameKey$
sendHTTPRequestASync(http, "update/index.php", vars$)
endfunction http
// Waits for response containing score data
function getScoreResponse(scoreObject)
res = getHTTPResponseReady(scoreObject)
scores$ = ""
if res = -1
// Error
elseif res = 1
scores$ = GetHTTPResponse(scoreObject)
endif
if res <> 0
closeHTTPConnection(scoreObject)
deleteHTTPConnection(scoreObject)
endif
endfunction scores$
// Waits for response after submitting score
function getSubmissionResponse(scoreObject)
res = getHTTPResponseReady(scoreObject)
if res = -1
// Error
elseif res = 1
res = val(GetHTTPResponse(scoreObject))
endif
if res <> 0
closeHTTPConnection(scoreObject)
deleteHTTPConnection(scoreObject)
endif
endfunction res
"I like offending people, because I think people who get offended should be offended." - Linus Torvalds