Create a button's icon with a part of a big image? - Beleaguered Castle

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Sun Oct 16, 2022 7:54 am

OK, now we know that the problem is not with the statistics display.
jacque wrote:
Sat Oct 15, 2022 5:57 pm
That's very strange. Could the game be updating the scores in more than one place? That might cause multiple additions.
It's an interesting clue. I checked: the "gameWonCount" counter is only incremented once, when the game is virtually won.

Code: Select all

on game_new
	...
   put the seconds into BCA_GAME_STATUS["gameid"]
   put 0 into BCA_GAME_STATUS["played"]
   put -1 into BCA_GAME_STATUS["movestowin"]
   put 0 into BCA_GAME_STATUS["movestowin"]
   put 0 into BCA_GAME_STATUS["fixedmoves"]
   statsUpdate "new"
end game_new

on game_won numCardsLeft  // valeur négative, ou 0 (win effectif), ou nbre cartes restantes (win assuré)
   put numCardsLeft into BCA_GAME_STATUS["movestowin"]
   if (numCardsLeft = 0) then
      if (userSettingsGet("prefs", "sounds") = 1) then get playSoundFile("Won.wav", "Sounds")
      answer "<b><font size=18 color=#9C5D14>Congratulations</font><font size=18>, you win!</font></b><br><br> " with \
            "OK" or "Quit" or "New Game" as sheet
      if (it = "New Game") then
         send "mouseUp" to btn "BtnNewGame"
      else if (it = "Quit") then
         quit
      end if
   else if (numCardsLeft > 0) then
      showTip true, "The game will be won in" && numCardsLeft && "moves."
      statsUpdate "won" // MAJ des stats (pas la peine de le refaire lors d'un win effectif)
      game_won_effect true // visual effect
   end if
end game_won

on statsUpdate event // "new", "won" ou "show"
   put userSettingsGet("prefs", "stats") into arrStats
   if (event = "new") then
      ------------------------------------------------------- new game
      add 1 to arrStats["gameLaunchedCount"]
   else if (event = "won") then
      ------------------------------------------------------- won game (virtual or effective)
      ----------------------------- stats générales
      add statsIsPlayed() to arrStats["gamePlayedCount"]
      add 1 to arrStats["gameWonCount"]
      put (the number of elements in BCA_HISTO) + BCA_GAME_STATUS["fixedmoves"] + BCA_GAME_STATUS["movestowin"] into \
            totalWinMoves
      ----------------------------- top scores
      -------- check si ID game n'existe pas
      local arrThisScore
      put false into idExists
      repeat for each element arrThisScore in arrStats["topScores"]
         if (arrThisScore["gameid"] = BCA_GAME_STATUS["gameid"]) then
            put true into idExists
            exit repeat
         end if
      end repeat
      if (not idExists) then // MAJ des top scores si ID game non trouvé dans les top scores
         put 10 into maxLines // 10 lignes de top scores max
         put "" into arrThisScore // ré-emploi
         put $USER into arrThisScore["name"]
         put BCA_GAME_STATUS["gameid"] into arrThisScore["gameid"]
         put the seconds into arrThisScore["date"]
         put arrThisScore into arrStats["topScores"][totalWinMoves]
         
         put the keys of arrStats["topScores"] into theKeys
         sort lines of theKeys ascending numeric
         delete line (maxLines + 1) to (the number of lines in theKeys) of theKeys
         local arrNewScores
         repeat for each line tKey in theKeys
            put arrStats["topScores"][tKey] into arrNewScores[tKey]
         end repeat
         put arrNewScores into arrStats["topScores"]
      end if
   else if (event = "show") then
      ------------------------------------------------------- show statistics (menu)
      add statsIsPlayed() to arrStats["gamePlayedCount"]
   end if
   ---------------------------------------------------------- update prefs user
   userSettingsSet arrStats, "prefs", "stats"
end statsUpdate

function statsIsPlayed // renvoit 1 si jeu en cours, ou 0 si le jeu en cours n'est pas taggé "played"
   if (the number of elements of BCA_HISTO > 0) then
      if (BCA_GAME_STATUS["played"] <> BCA_GAME_STATUS["gameid"]) then
         put BCA_GAME_STATUS["gameid"] into BCA_GAME_STATUS["played"] // flag pour non multiple updates du même jeu
         return 1
      end if
   end if
   return 0
end statsIsPlayed
I really wonder what actions you are doing Andreas that can cause this error.
Maybe the easiest way to solve this very strange behavior is to write a hotfix:

Code: Select all

if $USER = "Andreas" then divide gameWonCount by 8
;)

EDIT: I have a new clue... stay tuned.

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 265
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by SWEdeAndy » Sun Oct 16, 2022 8:40 am

Zax wrote:
Sun Oct 16, 2022 7:54 am
I really wonder what actions you are doing Andreas that can cause this error.
Maybe the easiest way to solve this very strange behavior is to write a hotfix:

Code: Select all

if $USER = "Andreas" then divide gameWonCount by 8
;)
Haha! :D Well, I don't know what my eccentric playing style might be...
I always manually finish games that can be won, for the satisfaction of completing the piles. I did try the auto-complete function some time ago, and it works well (though the animations gets a little choked).
I will experiment with quitting as soon as the game says it's a win, and see if that affects the win count in anyway. Or if auto-complete does.
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
WhenInSpace: https://wheninspace.se/en

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Sun Oct 16, 2022 9:24 am

SWEdeAndy wrote:
Sun Oct 16, 2022 8:40 am
I always manually finish games that can be won, for the satisfaction of completing the piles.
I never finish games manually, nor use the auto-complete command... Maybe the problem came from this difference.
So I built 0.35 version. I don't know if it will fix your problem but at least it fixes a bug with auto-complete and the way a game is considered as won.

Please delete your prefs file before using this new version.

https://sw.ixoft.com/files/BeleagueredC ... 35_OSX.zip
https://sw.ixoft.com/files/BeleagueredC ... 35_win.zip

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 265
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by SWEdeAndy » Sun Oct 16, 2022 9:48 am

Ah, I see it clearly now. The error does indeed occur as soon as you keep moving cards after the game is calculated as won. Then every new move adds to the win count, and since the game seems to normally be able to determine a win when there are 8 or less cards left, it makes every manually finished game add 8 to the win count!

Aah, the satisfaction of solving this mystery is even greater than winning the game like 8 times... 8)

So, the above was valid until v0.34. Let's see if v.0.35 solved it. :)
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
WhenInSpace: https://wheninspace.se/en

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Sun Oct 16, 2022 10:02 am

SWEdeAndy wrote:
Sun Oct 16, 2022 9:48 am
Ah, I see it clearly now. The error does indeed occur as soon as you keep moving cards after the game is calculated as won. Then every new move adds to the win count
Great!!!! :D
You're absolutely right, that's the reason.
And yes, 0.35 version should solve this stupid mistake, because the global BCA_GAME_STATUS has a new element "won", used as a flag to avoid considering the current game as won several times.

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 265
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by SWEdeAndy » Sun Oct 16, 2022 10:41 am

I confirm that in 0.35 the statistics seem to work flawlessly! Good job!
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
WhenInSpace: https://wheninspace.se/en

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Sun Oct 16, 2022 2:17 pm

Cool :)
Thank you for your patience and your motivation to fix this bug, Andreas.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7258
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by jacque » Sun Oct 16, 2022 5:36 pm

I love when we can do this for each other. So satisfying.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Wed Oct 19, 2022 8:18 am

jacque wrote:
Sun Oct 16, 2022 5:36 pm
I love when we can do this for each other. So satisfying.
Indeed :D
LC is great.
And this forum makes it even greater!


Concerning the Castle, I'm still not satisfied by the resizing. I'll try to improve it.

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Wed Nov 09, 2022 4:55 pm

0.38 is out.

It fixes some minor bugs, specially with the History, and above all the resizing is better.

Mac : https://sw.ixoft.com/files/BeleagueredC ... 38_OSX.zip
Win : https://sw.ixoft.com/files/BeleagueredC ... 38_win.zip

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 265
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by SWEdeAndy » Sun Jan 08, 2023 7:21 pm

Hey! New year, new issues! :D

Yes, I'm still playing this great game from time to time! Now, I've noticed a little issue with the statistics:

I have previously won a game at 82 moves:
BC1.png
BC1.png (28.73 KiB) Viewed 7869 times

Today I won again at 82 moves:
BC2.png
BC2.png (29.27 KiB) Viewed 7869 times
Expected behaviour would be that 82 occupies two places (with the newer one below the older one), and that 96 is pushed off the list.
Instead, the new occurrence of 82 has replaced the former one! :(
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
WhenInSpace: https://wheninspace.se/en

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Mon Jan 09, 2023 8:49 am

Happy new year!

I am really impressed by the quality and precision of your observations!
I always try to take care of the interface of my software but I must admit that I am far from having your rigor concerning debugging.
Thanks again Andreas, I will fix this problem soon.

My personal stats:

bc.jpg
bc.jpg (34.86 KiB) Viewed 7838 times

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Tue Jan 31, 2023 10:18 am

0.40 is out.

It fixes the Statistics bug pointed by Andreas and adds some minor improvements.

Mac : https://sw.ixoft.com/files/BeleagueredC ... 40_OSX.zip
Win : https://sw.ixoft.com/files/BeleagueredC ... 40_win.zip

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 265
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by SWEdeAndy » Tue Aug 08, 2023 7:38 pm

Hello Zax!

I still play this nice little game from time to time! :)
Today I did pretty well and made first place in the Hall of Fame with 77 moves! Only, it should have been just second place, as 77 was already at first place since a long time.
So, it seems there is still a small sorting bug when scores are tied (v0.44). It would need to sort on date and then score to get it right.
BC.png
The same can be observed for the 85 scores, while strangely not for the 90 scores.
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
WhenInSpace: https://wheninspace.se/en

Zax
Posts: 487
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image? - Beleaguered Castle

Post by Zax » Wed Aug 09, 2023 8:08 am

Thank you Andreas.
I'll try to fix this in future update.

BTW, your scores are amazing. Congratulations ! :)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”