1 Taking finger off the right arrow key slows down the sub, the sub keeps moving as I want it to despite removing finger from arrow key, not bringing it to an unrealistic abrupt stop.
2 Also pressing the opposite key to change direction takes some time for the sub to change direction as it slows down (trying to mimic reality) this works nicely
The Bad news:
1 When the sub actually stops to change direction it stops Tooo tooo long before changing direction - about 2 seconds actually it is about 3,3 seconds
2 I still can not discover how to limit the maximum speed despite Mark's kind offer of the min and max function, (which I have studied and read about But Yet still can not find any info really on how to use it within this contextual setting) maybe I am barking up the wrong tree with this and should be looking at something else?
in Button Start
Code: Select all
global subStartX
global subStartY
global subX
global subY
global subSpeedX
on mouseUp
   put initializesub() into Propel
   send RunSilent to me in 3000 milliseconds
end mouseUp
Code: Select all
global gsubStartX
global gsubStartY
global gsubX
global gsubY
global gsubSpeedX
on arrowKey theRudder
   if theRudder is "left" then
      put (gsubSpeedX - 0.05) into gsubSpeedX
   end if
   if theRudder is "right" then
      put (gsubSpeedX + 0.05) into gsubSpeedX
   end if
   --not working needs work - put max(gsubSpeedX - 0.1) into gsubSpeedX
   --and put min(gsubSpeedX + 0.1) into gsubSpeedX
   send RunSilent to me in 3000 milliseconds
   --trying to delay the command so that sub slows down gradually
end arrowKey
on RunSilent
   --The Loc has only two co-ordinates item 1 and 2
   --send these messages to object
   put item 1 of the location of button "sub" into gsubX
   put item 2 of the location of button "sub" into gsubY
   put (gsubX + gsubSpeedX) into gsubX
   --10 causes sub to bounce back from edge.  0 means sub just stops.
   if (gsubX <=35) then
      put 35 into gsubX
      put 0 into gsubSpeedX
   end if
   --100 here causes the sub still to stop, as does 25 but it does not bounce back
   --numbers from put command are screen limits
   if (gsubX >=770) then
      put 770 into gsubX
      put 0 into sgubSpeedX
   end if
   set the location of button "sub" to gsubX, gsubY
end RunSilent
function initializesub
   --screen positioning
   put 60 into gsubStartX
   put 200 into gsubStartY
   put gsubStartX into gsubX
   put gsubStartY into gsubY
   set the location of button "sub" to gsubX, gsubY
   --put 0 into gsubSpeedX - redundant code
   --this sets the stationary action of sub on start and also when arrow keys are pressed
end initializesub
 Happy to help, Chris!
 Happy to help, Chris!