"img" appears, moves back and fourth, disappears

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

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

"img" appears, moves back and fourth, disappears

Post by chris25 » Wed Oct 30, 2013 1:40 pm

Here are just two of the many syntaxes I have been trying. Trouble is I do not know whether I am using the wrong commands or wrong order or wrong commands in the wrong order....

I am simply trying to get a little humorous image to appear from behind a text field at the same time a little warning box appears (it is already hidden and behind the text field via a script in the preOpenCard Handler - no problem here), the image should then move up and down a couple of times and then disappear. I have been focusing on the repeat command and the hide and show commands. I have not set the properties box of the image to 'Hide' thinking this would be complicating the issue. I have tried quite a lot of manipulations over the last hour, Please do not give me the answer, yep - just a clue so that I can figure it out for myself. By the way, this first png screen shot marked 'first' locked my computer, am I that bad? :cry:

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: "img" appears, moves back and fourth, disappears

Post by Klaus » Wed Oct 30, 2013 4:34 pm

Hi Chris,

what you write and what you scripted so far do not tell the same story 8)

So let's see if we can find out what you really want:
1. user enters a value into a field
2. You check the field for VALUE between 500 and 5000
3. If that value is correct, NOTHING will happen in the "closefield" handler
4. If value is NOT correct, you want to:
a. answer something nice like "You are an idiot!"
b. move a little field X times up and down to visualize the users dumbness :D

Is that correct so far? If not, please write down what you have in mind.
As you can see, we could tranlate my list 1:1 to Livecode!

HINT:
Do NOT use a single "repeat" without any limitation like "with i = x..." etc.!
If you do not provide any "exit repeat" inside of the repeat loop, you are stuck
inside of an INFINITE (sic!) repeat loop and will have to KILL Livecode!


Best

Klaus

P.S.
Could you please post the "snapshot" code that makes your machine freeze?
I am sure we can sort this out!

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: "img" appears, moves back and fourth, disappears

Post by chris25 » Wed Oct 30, 2013 4:44 pm

Well Klaus - you are right about two things: it did freeze livecode once, and what I have written does no match my code - that's been my story the last two weeks :D Good news, i was just about to try the "repeat for" loop and keep it simpler. My challenge is to get it to synchronise with the appearance of the answer box that happily will be a kinder reply to the user :) Klaus 1 - 4a is working, it's B that I am still on (since this morning - Do I hear laughter in the background? No? Ah relief).

Don't say anymore, if I am stuck you will hear the scream across the Irish sea. Oh, thankyou for that hint.
Kind regards
Chris

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: "img" appears, moves back and fourth, disappears

Post by Klaus » Wed Oct 30, 2013 4:56 pm

Hi Chris,

well, that should be simple:
Move that image 3 times from -> a to b to a (so it doesnt "jump" back every time!)

Code: Select all

...
## Prepare the img to appear at the correct position:
set the loc of img "popup" to 215,85

## NOW show the image:
show img "popup"
repeat 3 
  ## or how often you like

  ## Move from a to b
  move img "popup from 215,85 to 215,63 in 200 millisecs
  ## 60 ticks = 1 second, which can be veeeeery loooooooooong for the user :-)
  ## Experiment with the number of repeats and the speed in millisecs!

  ## Move from b to back a
  move img "popup from 215,63 to 215,85 in 300 millisecs
end repeat

## Done, so:
hide img "popup"
...

Best

Klaus

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: "img" appears, moves back and fourth, disappears

Post by chris25 » Wed Oct 30, 2013 4:58 pm

Hi Klaus, did not see your code yet, but I actually got it to work - please with myself. However I still wonder whether tis is a good compact code that I have done, what is your opinion please?

on closefield
--  put me MESSAGE BOX SHOWS
      if me < 500 or me > 5000 then
        put empty into me
        answer error "Please enter a value between 500 and 5000" with "OK then" titled "pay attention twit"
repeat for 4 times
show img "popUp"
set the lockMoves to true
move img "popup" from 215,85 to 215,63 in 120 ticks without waiting
wait 30 ticks
move img "popup" from 215,63 to 215,85 in 120 ticks without waiting
wait 30 ticks
move img "popup" from 215,85 to 215,63 in 120 ticks without waiting
set the lockMoves to false
hide image "popUp"
end repeat
end if
end closefield

Veery Stange - suddnely it's not working, back to the drawing board

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: "img" appears, moves back and fourth, disappears

Post by Klaus » Wed Oct 30, 2013 5:13 pm

"lock moves" (= set the lockmovesto true) is only necessary
when you want to move more than ONE object at the same time
and it will stop the "movement" until you "unlock moves"!

That's why nothing happens in your script!
Remove the "set the lockmoves to true/false" from the code and all will be fine! :D

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: "img" appears, moves back and fourth, disappears

Post by Klaus » Wed Oct 30, 2013 5:18 pm

Code: Select all

on closefield
  if me < 500 or me > 5000 then
    put empty into me
    answer error "Please enter a value between 500 and 5000" with "OK then" titled "pay attention twit"

    ## Show and hide the image OUTSIDE of the repeat loop!
    show img "popUp"
    repeat for 4 times

      ## See below
      move img "popup" from 215,85 to 215,63 in 120 ticks without waiting
      wait 30 ticks
      move img "popup" from 215,63 to 215,85 in 120 ticks without waiting
      wait 30 ticks

      ## This line will make the first move JUMP! Know what I mean?
      ## See my last example script!
      ## But maybe this is what you want :-)
      move img "popup" from 215,85 to 215,63 in 120 ticks without waiting
    end repeat

    ## Show and hide the image OUTSIDE of the repeat loop!
    hide image "popUp"
  end if
end closefield

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: "img" appears, moves back and fourth, disappears

Post by chris25 » Wed Oct 30, 2013 5:24 pm

quick question since the tutorial pdf does not give the answer - where can I find the options/choices for the answer dialogue box the symbols I mean?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: "img" appears, moves back and fourth, disappears

Post by Klaus » Wed Oct 30, 2013 5:45 pm

ALWAYS check the dictionary! 8)

Check "ask" and "answer" and you will see all available options
including possible ICONS shown in the dialog.

You mean the ICONS displayed in the dialog, right?

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: "img" appears, moves back and fourth, disappears

Post by chris25 » Wed Oct 30, 2013 6:01 pm

Thanks - I have been staring at the dictionary for hours - it was not intuitive to think that typing in the answer command would show me how to change the icons, I was thinking drop down menu somewhere, anyway I am going doo la lilly here

on closefield
--  put me MESSAGE BOX SHOWS
      if me < 500 or me > 5000 then
        put empty into me
        answer error "Please enter a value between 500 and 5000" with "OK then"
show img "popUp"
repeat for 1 times
move img "popup" from 215,85 to 215,63 in 60 ticks without waiting
wait 1 secs
move img "popup" from 215,63 to 215,85 in 60 ticks without waiting
-- wait 1 secs
-- move img "popup" from 215,85 to 215,63 in 60 ticks without waiting
end repeat
hide image "popUp"
end if
end closefield

All I am getting is the sudden appearance of the image and its disappearence - I am trying all sorts of things and I am failing to see how your code and mine is different apart from secs and ticks.

I have stepped through all the breakpoints at every line at least three times with slight variations, and on all occaisions it does exactly what it is supposed to do, but when I try it on the stack, it fails miserably.

Also I looked in the dictionary but did not see anything (logical) that showed me how to access the answer box options/change icon types and appearance? sorry. I can not find it.

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

Re: "img" appears, moves back and fourth, disappears

Post by bn » Wed Oct 30, 2013 6:50 pm

Chris,
try

Code: Select all

on closefield
   --  put me MESSAGE BOX SHOWS
    if me < 500 or me > 5000 then
      put empty into me
      answer error "Please enter a value between 500 and 5000" with "OK then"
      show img "popUp"
      repeat for 1 times
         move img "popup" from 215,85 to 215,63 in 60 ticks
         move img "popup" from 215,63 to 215,85 in 60 ticks 
         move img "popup" from 215,85 to 215,63 in 60 ticks 
      end repeat
      hide image "popUp"
   end if
end closefield
Kind regards
Bernd

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: "img" appears, moves back and fourth, disappears

Post by chris25 » Wed Oct 30, 2013 7:53 pm

Hallo Bernd, well, rather disappointed that it works actually. It's perfect, many many appreciations. But now the depressing thing is that I did not ever think to get rid of all that redundant code.... :cry:

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

Re: "img" appears, moves back and fourth, disappears

Post by bn » Wed Oct 30, 2013 7:59 pm

Hello Chris,

the move command confuses me everytime I use it. I have to look it up and then test if I did understand and it works as I intended.
Too many options.

Kind regards
Bernd

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: "img" appears, moves back and fourth, disappears

Post by chris25 » Wed Oct 30, 2013 8:46 pm

I have just noticed a bug in livecode - seriously - when i first did your code into th ecard it worked perfectly. I then altered the x y co-ordinates and re-tried it. It failed, I double checked that nothing was changed it failed again, I fiddled and fiddled, (this happened with Klaus) So I closed down the program, re-opened, and it worked. Now since this happened twice I have to say that for some reason Livecode does not recognise the new co-ordinates after input, it retains the old info in the memory I would imagine and thinks hold on, that is not there anymore. Hey I'm just guessing. But the fact remains that after closing down livecode and restarting the stack worked again, so long that I do not re-edit the co-ordinates. If this is what I have been up against the whole day - Me thinks it not pleasant sir.

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

Re: "img" appears, moves back and fourth, disappears

Post by bn » Wed Oct 30, 2013 9:03 pm

Hi Chris,

I can not reproduce what you descibe, I change the coordinates, compile and run it, no problem.

Could you copy the code that does not work after you changed the coordinates and post it? Assuming that it compiles. You do run in Script Debug Mode, don't you? If you check that option in the development menu the debugger kicks in in case of a problem.

Kind regards
Bernd

Post Reply