Sunday, 31 March 2019

The Hangman game

You can download this game from  http://livecodeshare.runrev.com/download/stack/69/Hangman, it's the classic Hangman game:
It's a nice example of:
  • Custom graphic for buttons
  • Custom top bar
  • Custom shape windows (see the bottom window corners)
  • Windows slowly disappearing
Play with it and then I suggest you to study the code.

Saturday, 30 March 2019

Working with ZIP files

Livecode has the ZIP libraries integrated, so you can work with zip files.
In order to compress files or folder you have to use the absolute path of the new archive, example:

revZipOpenArchive "C:/myarchive.zip", "write"



Now you can add files and folders, just indicate the absolute paths inside the archive. You specify just files one by one, and directories are created by the path used, this is the code:

revZipAddItemWithFile "C:/myarchive.zip", "test.txt", "C:/Programs/RunRev/test.txt"
revZipAddItemWithFile "C:/myarchive.zip", "folder1/test.txt", "C:/Programs/RunRev/test.txt"
revZipAddItemWithFile "C:/myarchive.zip", "temp/folder2/test.txt", "C:/Programs/RunRev/test.txt"


After adding files, you have to close the archive, only at this point the ZIP file is correctly created:

revZipCloseArchive "C:/myarchive.zip"


In order to unzip files, first you have to get the list of files and folders, then you have to create all the folders needed on the destination filesystem, finally you can decompress files. For example, this is the code to do it on Windows:

on mouseUp
   answer file "Select Zip file to decommpress:"
   put it into myzip
   revZipOpenArchive myzip,"read"
   put revZipEnumerateItems(myzip) into tItems
   repeat for each line tline in tItems
      if last char of tline is "/" then
         create folder "C:/Documents and Settings/max/Desktop/" & tline
      else         
         put "C:/Documents and Settings/max/Desktop/" & tline into temp
         revZipExtractItemToFile myzip, tline, temp
      end if
   end repeat
   revZipCloseArchive myzip
end mouseUp

You can modify the above code for your needs.

Saturday, 23 March 2019

Changing window shape

If you want a custom window shape, like this:

instead of this:

You have to import the image backgroud, this image must have transparent parst like a GIF or a PNG.
Then you have to set the windowshape of the stack to the imported image, using the property inspector. Finished.
Unfortunately you have no more the icons to iconify or close the window, ho you have to add these buttons:


Now add the following code in the close button:
on MouseUp
   quit
end MouseUp

and this code in the iconify button:
on mouseUp
   set the iconic of this stack to true
end mouseUp

Now add this code in the stack to move it:
on mouseStillDown   
   set the loc of this stack to globalloc(the mouseLoc)
end mouseStillDown
   

Friday, 15 March 2019

Toggle button

One of the missing controls in Livecode palette is the toggle button.
To obtain a toggle button, just add this code to a button:


on MouseUp
   put the hilite2 of me into hitemp
   if hiTemp then
      set the hilite2 of me to false
   else
      set the hilite2 of me to true
   end if
end MouseUp

setprop hilite2 temp
   set the hilite of me to temp
   set the hilite2 of me to temp
end hilite2

I used a new property, because the hilite is actived as soon you press but you still don't relase the mouse.

Thursday, 14 March 2019

Animation with drawing

You can create an animation with the drawing commands of livecode, for example see this script:

on mouseUp
   set the rect of the templateImage to 100,100,400,400
   create image "test"
   choose brush tool
   set the brush to 8
   set the brushColor to red -- could use an RGB triplet here
   set the dragSpeed to 20 -- very slow
   #H
   drag from 120,120 to 120,300
   drag from 120,200 to 150,200
   drag from 150,300 to 150,120
   #i
   drag from 180,120 to 180,150
   drag from 180,180 to 180,300     
end mouseUp

this is the result:

The example is simple, but you can use all geometric shapes of livecode, so you can create very complex animations.