Custom variables for a leaderboard?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Custom variables for a leaderboard?
Hello, I am trying to create a multiplayer game which is basically a trivia, at the start the players have to enter the amount of players engaging in the game, I want that as soon as they do that, the game will create a variable for each of them, for example variable number 12 for player number 12 and then everytime there is a question, the computer will choose a random player (already know and did that using the random() ), but how do I add a leaderboard and how do I make the computer read and understand the random player and assign him to his variable?
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Custom variables for a leaderboard?
Hi Itay,
I think an array could do what your describe. The main index would be the player number
in this script I create an array with the number of players indicated and assign each playe a random score. This score is then queried and displayed in a field
Since I put the Array into a script local variable sPlayerArray it could be accessed from any handler in the script. Of course you could also make this a global variable.
I think an array is the easiest way to do this but you would have to make yourself familiar with arrays
If you don't want to go with arrays you could also use an itemized list.
i.e. make a list with a number on each line, then you could put the score into item 2 of that line
this is essentially the same as the first piece of code, just using a list, and I put the list into a global variable this time.
Kind regards
Bernd
I think an array could do what your describe. The main index would be the player number
in this script I create an array with the number of players indicated and assign each playe a random score. This score is then queried and displayed in a field
Since I put the Array into a script local variable sPlayerArray it could be accessed from any handler in the script. Of course you could also make this a global variable.
Code: Select all
local sPlayerArray
on mouseUp
ask "how manu players?"
if it is not a number then exit mouseUp -- check the input more thoroughly
put it into tPlayers
repeat with i = 1 to tPlayers
put random (50) into sPlayerArray[i]["score"]
end repeat
put the keys of sPlayerArray into tPlayerKeys
put random (the number of lines of tPlayerKeys)into tRandomPlayer
put sPlayerArray[tRandomPlayer]["score"] into tRandomPlayerScore
put "RandomPlayer number :" & tRandomPlayer & cr & "score of player " & tRandomPlayer & ": " & tRandomPlayerScore into field 1
end mouseUp
If you don't want to go with arrays you could also use an itemized list.
i.e. make a list with a number on each line, then you could put the score into item 2 of that line
Code: Select all
global gPlayerList
on mouseUp
ask "how manu players?"
if it is not a number then exit mouseUp -- check the input more thoroughly
put it into tPlayers
repeat with i = 1 to tPlayers
put i & return after gPlayerList
put random (30) into item 2 of line i of gPlayerList
end repeat
put random ( the number of lines of gPlayerList) into tRandomPlayer
put item 2 of line tRandomPlayer of gPlayerList into tRandomPlayerScore
put "RandomPlayer number :" & tRandomPlayer & cr & "score of player " & tRandomPlayer & ": " & tRandomPlayerScore into field 1
end mouseUp
Kind regards
Bernd
Re: Custom variables for a leaderboard?
Thanks bn, may I also know how to create a clock timer, for example:
it starts to count from 0:00 while the left stands for hour and right stands for minutes, every hour equals one minute in real life, while every minute equals one second in real life, and as soon as the clock reaches 2 hours, something happens.
it starts to count from 0:00 while the left stands for hour and right stands for minutes, every hour equals one minute in real life, while every minute equals one second in real life, and as soon as the clock reaches 2 hours, something happens.
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Custom variables for a leaderboard?
Hi Agent,
don't tell anybody that I gave you this code, but for doing a non-blocking timer you have to get your head around the "send "command" in xxx timeUnits" constructs. Otherwise the timer would block your game.
you also should know how a script local variable works, the three script local variables I use are declared above the handlers. There are other ways to do all this, this is one way.
Kind regards
Bernd
don't tell anybody that I gave you this code, but for doing a non-blocking timer you have to get your head around the "send "command" in xxx timeUnits" constructs. Otherwise the timer would block your game.
you also should know how a script local variable works, the three script local variables I use are declared above the handlers. There are other ways to do all this, this is one way.
Code: Select all
local sTimerIsRunning = false, sMinutes, sSeconds
on mouseUp
put true into sTimerIsRunning
put 0 into sMinutes
put 0 into sSeconds
send "startTimer" to me in 0 milliseconds
end mouseUp
on startTimer
if sTimerIsRunning then
add 1 to sSeconds
if sSeconds = 60 then
put 0 into sSeconds
add 1 to sMinutes
end if
if sSeconds < 10 then
put "0" & sSeconds into tDisplaySecs
else
put sSeconds into tDisplaySecs
end if
put sMinutes & ":" & tDisplaySecs into field "fRes"
if sMinutes = 2 then
put false into sTimerIsRunning
send "bingo" to me in 0 milliseconds
exit startTimer
end if
send startTimer to me in 1 second
end if
end startTimer
on Bingo
put cr & "Game over" after field "fRes"
end Bingo
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Custom variables for a leaderboard?
Hey Everybody Look Here ^^^^
Bernd is giving away code!
Bernd helps people
Simon
Bernd is giving away code!
Bernd helps people
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Custom variables for a leaderboard?
OK, that's it. I am going to start giving away code as well.
Simon? Don't hate me.
Craig
Simon? Don't hate me.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Custom variables for a leaderboard?
Simon, you blew it. Now everybody knows about it. It was supposed to be a secret between agentItay and me.Bernd is giving away code!
Of course that was a one time raffle.
Because today is "BlackCodingThursday"
Kind regards
Bernd
and because I am in a give away mood:
here is a version that syncs the timer to the system and additional bonus: it tells you how many milliseconds it is off the real second. This one is less prone to suffer delays from other stuff that is going on while the game is on and will catch on to the real second.
Code: Select all
local sTimerIsRunning = false, sMinutes, sSeconds, sStartMillisecs
on mouseUp
put true into sTimerIsRunning
put 0 into sMinutes
put 0 into sSeconds
put (1000 - char -3 to - 1 of the milliseconds) into tWhen
send "startTimer" to me in tWhen milliseconds
put the milliseconds - (1000 - tWhen) into sStartMillisecs
end mouseUp
on startTimer
if sTimerIsRunning then
add 1 to sSeconds
if sSeconds = 60 then
put 0 into sSeconds
add 1 to sMinutes
end if
if sSeconds < 10 then
put "0" & sSeconds into tDisplaySecs
else
put sSeconds into tDisplaySecs
end if
put the milliseconds - sStartMillisecs - ((sSeconds + sMinutes *60)*1000) into tDiffSec
put sMinutes & ":" & tDisplaySecs && tDiffSec into field "fRes"
if sMinutes = 2 then
put false into sTimerIsRunning
send "bingo" to me in 0 milliseconds
exit startTimer
end if
put 1000 - char -3 to - 1 of the milliseconds into tWhen
send startTimer to me in tWhen milliseconds
end if
end startTimer
on Bingo
put cr & "Game over" after field "fRes"
end Bingo
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Custom variables for a leaderboard?
Great.
Just Great.
Next you two will be helping people without being paid for it, have conversations with complete strangers, be part of a community.
I miss the good old days.
Bah i say... Bah
Simon
Just Great.
Next you two will be helping people without being paid for it, have conversations with complete strangers, be part of a community.
I miss the good old days.
I'll go as far as to predicted that by the end of this month the pair of you will be giving gifts, signing cards to people you barely speak to all year. Spreading good will and cheer to all men.Hi [Insert name here], this should help you outCode: Select all
on mouseUp put base64Decode("RmlndXJlIGl0IG91dCB5b3Vyc2VsZg==") end mouseUp
Bah i say... Bah
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Custom variables for a leaderboard?
Hahaha, thanks Bernd.
Re: Custom variables for a leaderboard?
I need a bit more help (even though its not BlackCodingThursday ).
1. I want the timer to do the following: If it is higher than 1:00, than it will display "It is now 1:00" and if it is higher than 2:00 it will display "it is now 2:00", when I did that it created a loop because 2:00+ is still higher than 1:00, so it just messes everything up.
2. I want to make some things with the grab option, I already did that, but I want to set the users to only be able to grab the object within a limited area in the screen, for example:
-------- - - - - -- - |--------------------------
| USERS CAN |
| GRAB HERE | CANT HERE
|--------- - - - -- -- -----------------------------
1. I want the timer to do the following: If it is higher than 1:00, than it will display "It is now 1:00" and if it is higher than 2:00 it will display "it is now 2:00", when I did that it created a loop because 2:00+ is still higher than 1:00, so it just messes everything up.
2. I want to make some things with the grab option, I already did that, but I want to set the users to only be able to grab the object within a limited area in the screen, for example:
-------- - - - - -- - |--------------------------
| USERS CAN |
| GRAB HERE | CANT HERE
|--------- - - - -- -- -----------------------------
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Custom variables for a leaderboard?
You would have to post an example of your code to illustrate what you are doing. Do you know that you can restrict to a range of values in a conditional statement?1. I want the timer to do the following: If it is higher than 1:00, than it will display "It is now 1:00" and if it is higher than 2:00 it will display "it is now 2:00", when I did that it created a loop because 2:00+ is still higher than 1:00, so it just messes everything up.
if x >= 1 and x < 2 then
if x >= 2 then
I suppose you put "grab me" into a mouseDown handler, before "grab me" you can test for a location of the control and exit mouseDown if the location is not within you predetermed boundaries.2. I want to make some things with the grab option, I already did that, but I want to set the users to only be able to grab the object within a limited area in the screen, for example:
Kind regards
Bernd
Re: Custom variables for a leaderboard?
Thanks.bn wrote:You would have to post an example of your code to illustrate what you are doing. Do you know that you can restrict to a range of values in a conditional statement?1. I want the timer to do the following: If it is higher than 1:00, than it will display "It is now 1:00" and if it is higher than 2:00 it will display "it is now 2:00", when I did that it created a loop because 2:00+ is still higher than 1:00, so it just messes everything up.
if x >= 1 and x < 2 then
if x >= 2 then
I suppose you put "grab me" into a mouseDown handler, before "grab me" you can test for a location of the control and exit mouseDown if the location is not within you predetermed boundaries.2. I want to make some things with the grab option, I already did that, but I want to set the users to only be able to grab the object within a limited area in the screen, for example:
Kind regards
Bernd
And about the second one, I put "grab me" into a mouseStillDown handler, and before the "grab me" I put a "if intersect(me, X) blablabla."
and it is working, but if I move it too fast, it will eventually let me move it out of the given location.
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Custom variables for a leaderboard?
Hi,
I think to put the test on a mouseStillDown message is too slow, mouseStilldown is only sent on idle, see idleRate in the dictionary.
By default it is sent every 200 milliseconds. You could lower the idleRate but at idle a lot of things happen that you really probably would not have to happen quite so often (LC does cleaning up on idle)
By contrast mouseMove would be a good message to do your checks.
Try this with a button or graphic or whatever.
you can see the milliseconds it takes for the roundtrip while moving. Here you could do your conditionals.
Kind regards
Bernd
I think to put the test on a mouseStillDown message is too slow, mouseStilldown is only sent on idle, see idleRate in the dictionary.
By default it is sent every 200 milliseconds. You could lower the idleRate but at idle a lot of things happen that you really probably would not have to happen quite so often (LC does cleaning up on idle)
By contrast mouseMove would be a good message to do your checks.
Try this with a button or graphic or whatever.
Code: Select all
local sMoving
local sLastMS = 0
on mouseDown
put true into sMoving
grab me
end mouseDown
on mouseMove
if not sMoving then exit mouseMove
put the milliseconds - sLastMS into field "fRes"
put the milliseconds into sLastMS
end mouseMove
on mouseUp
put false into sMoving
end mouseUp
on mouseRelease
mouseUp
end mouseRelease
Kind regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Custom variables for a leaderboard?
Hi Itay,
here is a stack that constrains an object to an arbitrary boundary when it is dragged.
This is not "intersect", just stop at the border.
Have a look at the code, it uses mouseMove. It does not use "grab me". This way you have better control over locating the object within boundaries.
Kind regards
Bernd
here is a stack that constrains an object to an arbitrary boundary when it is dragged.
This is not "intersect", just stop at the border.
Have a look at the code, it uses mouseMove. It does not use "grab me". This way you have better control over locating the object within boundaries.
Kind regards
Bernd
- Attachments
-
- constrainObject.livecode.zip
- (1.78 KiB) Downloaded 179 times
Re: Custom variables for a leaderboard?
Thank you very much Bernd.
And last thing, I am planning to release something I developed using Livecode community, what should I include in my .zip file? Only my .exe file (of course ) my .livecode file, this thing of the GNU license (edited to my needs of course)
And that's it? (Also, I can see that it says " and each file should have at least the “copyright” line and a pointer to where the full notice is found." Should I direct them to this? (http://www.gnu.org/licenses/gpl-3.0.en.html) or should I include another text file in my .zip folder including the entire text here (http://www.gnu.org/licenses/gpl-3.0.en.html)? Thanks in advance and sorry for all of those questions, that's my first time to release an application, and licenses issues are the last thing I want to run into. )
And last thing, I am planning to release something I developed using Livecode community, what should I include in my .zip file? Only my .exe file (of course ) my .livecode file, this thing of the GNU license (edited to my needs of course)
Code: Select all
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.