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: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Fri Aug 26, 2022 2:55 pm

The project is progressing well, I'm now in an optimization phase.

Regarding my latest problem, I found the faulty operation: when opening the stack, I redraw all the gaming cards from images residing in a substack. This operation is a bit slow on my old machine and the problem is that the last line of the script is skipped/forgotten, without any pending message.

Code: Select all

on board_redrawCards
   repeat for each item thisImage in myImageList
      set the text of img thisImage to (the text of img thisImage of card "GamingCards" of stack "GamingCardsStack")
   end repeat
   
   doOtherStuff //////// IGNORED !!!
end board_redrawCards
If wait... with messages is added, doOtherStuff statement is well processed.

Code: Select all

on board_redrawCards
   repeat for each item thisImage in myImageList
      set the text of img thisImage to (the text of img thisImage of card "GamingCards" of stack "GamingCardsStack")
   end repeat
   
   wait 500 milliseconds with messages ////////// how long I have to wait ???
   doOtherStuff
end board_redrawCards
The real question is how long should I wait. It depends on the machine.
OK, but how to know if the loop is finished and the script can continue, knowing that any statement following the loop is ignored if there is no wait... with message?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

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

Post by jacque » Fri Aug 26, 2022 8:59 pm

Does this work:

Code: Select all

on board_redrawCards
   lock screen
   repeat for each item thisImage in myImageList
      set the text of img thisImage to (the text of img thisImage of card "GamingCards" of stack "GamingCardsStack")
   end repeat
   unlock screen
   send "doOtherStuff" to me in 1 millisecond
end board_redrawCards
The theory is that LC needs an idle period to redraw the images, and using "send in time" allows that. The board_redrawCards handler should run fairly quickly if you lock the screen, and calling "doOtherStuff" after a short delay should execute after the loop finishes. This way you don't need to guess how long to wait, the other stuff won't happen until the first handler finishes.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Sat Aug 27, 2022 10:36 am

It's better. But 1 ms is still not enough: I tried with 100 ms with success.
In fact, I already locked the screen before changing images' text but the unlock screen command was placed at the end of doOtherStuff statement.
But you're right Jacqueline, SVG process doesn't take much time, so it's all still a bit of a mystery.

Anyway, I repeat, it's much better now, and it works. :)

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Sat Aug 27, 2022 1:53 pm

OK, this is it! At least a beta version.

The main features I wanted are present (choice of board and card graphics). The cards movements are not very smooth on my machine but it should be fine on newer machines.

I've wanted to make a Beleaguered Castle Solitaire for a long time - you can find some on the web but they are often very ugly or not very pleasant to use.
I couldn't have done it without your help, so again a very big thank you to everyone! :D

bca3.jpg

MacOS standalone: https://sw.ixoft.com/files/BeleagueredC ... 05_OSX.zip
Windows standalone: https://sw.ixoft.com/files/BeleagueredC ... 05_win.zip

Also, for those who would be interested, I have 2 sets of cards in SVG - one file per card:
Standard: https://sw.ixoft.com/files/_OLD/Playing ... andard.zip
Textured: https://sw.ixoft.com/files/_OLD/Playing ... xtured.zip

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

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

Post by jacque » Sat Aug 27, 2022 5:11 pm

Did you ever figure out what was causing the delay? I'm curious.

I've never played Beleaguered Castle but you've got me interested. You did spur me to pull out my old solitaire game, based on one called Sir Tommy, and I've been experimenting with turning it into a web app. I also have an old Klondike game I might tinker with.

I'll give your game a try. Congratulations!
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10092
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Sat Aug 27, 2022 6:11 pm

Fantastic . . .

. . . makes me feel bad about my half-finished Onitama.

Back in Bulgaria on 31st, rubbish preterm before 8th, teaching starts on the 8th. Hope by the following week things will have calmed down and I can . . .

You may think you have learnt a few things from me, BUT I think I have learnt at least as much from you.

Oh, and as, while on holiday I only have my Linux 64-bit laptop, could be extra kind and make a Linux 64 standalone?

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Sun Aug 28, 2022 1:19 pm

Thank you for your comments, I appreciate :)
(and I also thank you to be so patient for my "exotic" english).
What I appreciate in Beleaguered Castle is the balance between chance and reflection. After the random draw of the cards, it becomes a puzzle game.

Jacqueline, concerning the mysterious delay, I finally had to roll back to my previous version with a wait for 500 ms with messages.
Maybe the solution could be:

Code: Select all

on openingStuff
doSomeStuff
send "board_redrawCards" to me in 10 milliseconds // 53 images from 15 to 920 ko !
doOtherStuff
end openingStuff
richmond, I compiled a Linux version... without any guarantee because I'm unable to test Linux version.

A new version is available. It fixes some minor bugs :
MacOS standalone: https://sw.ixoft.com/files/BeleagueredC ... 06_OSX.zip
Windows standalone: https://sw.ixoft.com/files/BeleagueredC ... 06_win.zip
Linux standalone: https://sw.ixoft.com/files/_OLD/Beleagu ... _linux.zip

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4170
Joined: Sun Jan 07, 2007 9:12 pm

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

Post by bn » Sun Aug 28, 2022 5:00 pm

Hi Zax,

I like the design of your game and the game looks great and works for me on a fast Mac without a hitch.


Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10092
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Sun Aug 28, 2022 7:00 pm

Screenshot_2022-08-28_20-58-32.png
-
Something not quite right.

The 'trick' is to get hold of an old, unwanted PC and install Xubuntu on it: perfect for testing. 8)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

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

Post by jacque » Sun Aug 28, 2022 8:11 pm

I ran your game on my iMac and it was smooth and worked very well. Very nice implementation. You thought of all the tricks to make the game easily functional.

I only saw one thing that wouldn't reproduce; after clicking a card to auto-play it, the window size changed slightly, back to a default size I think. I resized it a bit larger and after that it stayed that way. That's a minor thing though, you did a great job. I haven't tried your revised release yet but I will.

Have you ever won this game? Several deals produced Kings at the end of several rows and no playable cards elsewhere.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Sun Aug 28, 2022 10:39 pm

richmond62 wrote:
Sun Aug 28, 2022 7:00 pm
Something not quite right.

The 'trick' is to get hold of an old, unwanted PC and install Xubuntu on it: perfect for testing. 8)
I’m guessing this isn’t something the author can do much about. I guess it could be something funky with 10.0.0 DP4, and it may be worth rebuilding the Linux standalone with 9.6.8 stable, but not being able to load the gdk library may well be due (and I’m completely guessing here) to the particular flavour of Linux or setup for example.

Googling gdk:
https://en.wikipedia.org/wiki/GDK?wprov=sfti1

This falls under the category of Linux gobbledygook for me, but i suspect it’s something to do with Linux setup or the way LiveCode builds for Linux rather than something with the the code… don’t think the author can resolve this. May be worth opening a support ticket…

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Mon Aug 29, 2022 6:46 am

Glad to hear the game doesn't seem too jerky on newer machines. :)

Jacqueline, the adaptative board size has been a problem for me since the start of development. I tried numerous thing without yet finding a good solution.
And yes, the game is winnable. I win about 1 game out of 6. The trick is to empty rows. Once you have 2 empty rows, you are on your way to winning.
This is for example a game I recently played, and win after 122 moves. Just put the savedgame file into your Preferences folder and launch the game. You can use the history back to see the cards mouvements, or Reload Game to see its initial state.
BCastle_Savegame.ixp.zip
(1.29 KiB) Downloaded 123 times

Sorry richmond but I haven't enough time and strength to explore Linux world.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10092
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Mon Aug 29, 2022 10:21 am

Please try a build as suggested with 9.6.8.

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Mon Aug 29, 2022 2:46 pm

richmond62 wrote:
Mon Aug 29, 2022 10:21 am
Please try a build as suggested with 9.6.8.
The standalone Linux version I posted was made with LC MacOSX 9.6.8 stable.
lin.jpg

What do you want me to do exactly?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

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

Post by jacque » Mon Aug 29, 2022 5:09 pm

Maybe he needs the x64 build? I'm not sure you need the Inclusions either.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply