Page 1 of 1

Overdrive Bonus

Posted: Wed Feb 09, 2022 10:08 pm
by Samuele
Hi, I'm trying to make an overdrive bonus, that doubles the value of the points after the user clicks on an object for 20 times, i thought this script works well but sometimes, i see errors and i can't figure out why (for example the thumbPosition does not restart after 20 clicks ecc... one of the bugs i think happens when the user clicks on the "minus" object i will write here its script) another thing i did, is an overdrive minus, that when the user clicks on a "minus" object it takes back the overdrive bonus one number back.
this is the script:
overdrive bonus (when the user clicks on the target object)

Code: Select all

on UpdateOverDriveClickBonus
   add 1 to _sessionClicks
   add 1 to _sessionClicks2
   set the thumbPosition of scrollbar "ProgressOverDrive" to (_sessionClicks2 - _alreadyDid)
   put CalculateOverDriveBonus() into _overDriveBonus
   put CalculateOverDriveBonus2() into _overDriveBonus2
   if _overDriveBonus2 is an integer
   then
      put "X" & _overDriveBonus2 into field "overDriveBonus"
      ShowBetterOverDrive
   else
   end if
end UpdateOverDriveClickBonus


function CalculateOverDriveBonus2
   return (_sessionClicks / 20 ) +1
end CalculateOverDriveBonus2


function CalculateOverDriveBonus
   return trunc (_sessionClicks / 20 ) +1
end CalculateOverDriveBonus


on ShowBetterOverDrive
   if _overDriveBonus > 1
   then
      --resetta lo scrollbar a 0
      set the thumbPosition of scrollbar "ProgressOverDrive" to 0
      --resetta il numero dei click
      #put empty into _sessionClicks2
      --aggiungi 20 nel variable dei già fatt
      add 20 to _alreadyDid
      --set the size of fld "overDriveBonus" to più grande
      set the textSize of fld "overDriveBonus" to 115
      set the width of fld "overDriveBonus" to 150
      set the height of fld "overDriveBonus" to 130
      set the loc of fld "overDriveBonus" to 160,80
      send RepositionOverDrive to me in 1.5 seconds
   else
   end if
end ShowBetterOverDrive


on RepositionOverDrive
   --resize
   set the textSize of fld "overDriveBonus" to 30
   set the width of fld "overDriveBonus" to 46
   set the height of fld "overDriveBonus" to 31
   --relocate
   set the location of fld "overDriveBonus" to 285,18
end RepositionOverDrive
overdrive minus (when the user clicks on a "minus" object)

Code: Select all

on OverDriveMinus
   if _overDriveBonus2 > 1
   then
      --quelli che si vedranno
      put empty into _sessionClicks2
      put empty into _alreadyDid
      --
      put the thumbPosition of scrollbar "ProgressOverDrive" into tInPiu
      put (_sessionClicks - 20 - tInPiu) into _sessionClicks
      put (_overDriveBonus2 - 1) into _overDriveBonus2
      #if _alreadyDid > 20
      #then
         #put (_alreadyDid - 20) into _alreadyDid
         #set the thumbPosition of scrollbar "ProgressOverDrive" to 0
      else
      end if
   if _overDriveBonus > 1
   then
      put (_overDriveBonus - 1) into _overDriveBonus
      put "X" & _overDriveBonus into field "overDriveBonus"
   else
   end if
   set the thumbPosition of scrollbar "ProgressOverDrive" to 0
end OverDriveMinus
the script of the target object: (the other handlers, i don't think they're relevant)

Code: Select all

local sLocationOf

on mouseDown
   ClickMe
   aeMoveDone
   displayPlus
end mouseDown

on aeMoveDone
   get the location of me
   put it into sLocationOf
end aeMoveDone


on ClickMe
   dispatch UpdateScore with 5
   UpdateOverDriveClickBonus
   HandleBonusObject
end ClickMe


on displayPlus
   show fld "PlusOneHeader"
   set the location of fld "PlusOneHeader" to sLocationOf
   send "HideHeader" to me in 0.25 seconds
end displayPlus


on HideHeader
   hide fld "PlusOneHeader"
end HideHeader
the "minus" object script:

Code: Select all

local sLocationOf

on mouseDown
   ClickMinus100
   aeMoveDone
   displayMinus
   mobileVibrate
end mouseDown


on aeMoveDone
   get the location of me
   put it into sLocationOf
end aeMoveDone


on ClickMinus100
   dispatch UpdateScoreMinuses with -5
   OverDriveMinus
end ClickMinus100


on displayMinus
   show fld "minusHeader"
   set the location of fld "minusHeader" to sLocationOf
   send "HideHeader" to me in 0.2 seconds
end displayMinus


on HideHeader
   hide fld "minusHeader"
end HideHeader
(if you think there's an easier way to make all this happen the right way please, do tell)
any help would be helpful!
Thanks!

Re: Overdrive Bonus

Posted: Thu Feb 10, 2022 5:58 am
by dunbarx
Hard for me to get going with your issue with only the handlers. Post the stack.

Craig

Re: Overdrive Bonus

Posted: Thu Feb 10, 2022 9:21 am
by richmond62
Seems complicated.

-
SShot 2022-02-10 at 10.19.41.png
-

Code: Select all

on mouseUp
   add 1 to fld "fPOINTS"
   put fld "fPOINTS" into SCORE
   if SCORE > 19 then
      set the vis of grc "BANG!" to true
   end if
end mouseUp

Re: Overdrive Bonus

Posted: Thu Feb 10, 2022 11:37 am
by Klaus
Hi Samuele,

what Craig said!

Hint:
You can save two lines in your scripts:
1. do not put THEN in an extra line, this will do:

Code: Select all

if whatever = 1 then...
2. if you don't have an ELSE case, no need to write ELSE! :-)

Code: Select all

if whatever = 1 then
  ## do this
end if
Best

Klaus

Re: Overdrive Bonus

Posted: Sat Feb 12, 2022 9:01 pm
by Samuele
alright, that's the stack:
clickMe.zip
(6.69 KiB) Downloaded 163 times
Thanks!

Re: Overdrive Bonus

Posted: Sun Feb 13, 2022 10:20 am
by richmond62
Great functionality, but:
-
SShot 2022-02-13 at 11.18.27.png

Re: Overdrive Bonus

Posted: Sun Feb 13, 2022 6:41 pm
by dunbarx
Samuele.

I see you are well along in using Livecode. Excellent. Really.

But I have a feeling that the functionality you need could be built with a far smaller script. But before I say that, since I could be very wrong, can you make a short list of what your stack is required to do? This is called a functional spec. It would look something like this:

1- If the user does one kind of thing, then doThis
2- If the user does a different kind of thing, then doThat
3- if an output reaches a certain value, then doSomethingElse
4- If somethingElseHappens, then do yetAnotherThing

And feel free to ignore this entirely. It is only an exercise for me, and maybe for you, to explore how things can be done in LiveCode in different ways. That is one of its most endearing features.

Craig

Re: Overdrive Bonus

Posted: Mon Feb 14, 2022 8:58 am
by richmond62
I have a lot of questions . . .
-
SShot 2022-02-14 at 9.56.08.png

Re: Overdrive Bonus

Posted: Wed Feb 16, 2022 4:51 pm
by Samuele
dunbarx wrote:
Sun Feb 13, 2022 6:41 pm
Samuele.

I see you are well along in using Livecode. Excellent. Really.

But I have a feeling that the functionality you need could be built with a far smaller script. But before I say that, since I could be very wrong, can you make a short list of what your stack is required to do? This is called a functional spec. It would look something like this:

1- If the user does one kind of thing, then doThis
2- If the user does a different kind of thing, then doThat
3- if an output reaches a certain value, then doSomethingElse
4- If somethingElseHappens, then do yetAnotherThing

And feel free to ignore this entirely. It is only an exercise for me, and maybe for you, to explore how things can be done in LiveCode in different ways. That is one of its most endearing features.

Craig
First of all thanks, I'll try.
so i feel like i need to say this, the stack i shared is only a part of my original stack that i changed in order to leave only the objects/scripts ecc. relevant to this specific question, so if it seems like something useless, with no point or if colors/graphic isn't the right one, it's because i didn't set my focus on that, (
richmond62 wrote:
Sun Feb 13, 2022 10:20 am
Great functionality
,
richmond62 wrote:
Mon Feb 14, 2022 8:58 am
I have a lot of questions . . .
)
So for the list, do you mean here on the forum or in the script AKA "Documentation"?
in general this is what the stack should do:

1- when the user clicks on the click me button it adds 5 points to the score
1.5- and it increases the current value of the scrollbar to the appropriate variable

2- when the user clicks on the minus button it subtracts 5 points from the score

3- after the user clicks 20 times consecutively on the click me button the x1 sign becomes x2 and every click of the click me button becomes 10 points (times 2) and so on... (if the sign is x2 it becomes x3 and every click on the click me button becomes 15 points...)

4- if the user clicks on the minus button when the thumbposition of the scrollbar is greater than 1 (in the script i have put this value in a variable), that means the user clicked on the click me button then the thumbposition of the scrollbar will become 0

5- if the user clicks on the minus button when the thumbposition of the scrollbar is 0 (start value) and the sign is greater than 1 (x1) then, the sign will become -1 of the current ( if it is x3 it will become x2 and so on...)

6- when i say 'the sign' i don't mean only the field but also the variable that multiplies the points


I think this is in general what the stack should do without going into detail about the variables and the appropriate codes.
Thanks!

Re: Overdrive Bonus

Posted: Wed Feb 16, 2022 5:50 pm
by dunbarx
I understand.

A functional spec is just a summary of the requirements for the project. It may not be worth exploring, but I just have a feeling that, unless there is a great deal of functionality that I do not see, the scripts could be massively simplified.

Do not sweat this.

Craig

Re: Overdrive Bonus

Posted: Tue Mar 01, 2022 11:46 am
by Samuele
dunbarx wrote:
Wed Feb 16, 2022 5:50 pm
I understand.

A functional spec is just a summary of the requirements for the project. It may not be worth exploring, but I just have a feeling that, unless there is a great deal of functionality that I do not see, the scripts could be massively simplified.

Do not sweat this.

Craig
is it understandable now? 👆

bonus for clicks

Posted: Wed Mar 09, 2022 7:43 pm
by Samuele
Hi, I'm trying to make an overdrive bonus, that doubles the value of the points after the user clicks on an object for 20 times, i thought this script works well but sometimes, i see errors and i can't figure out why (for example the thumbPosition does not restart after 20 clicks ecc... one of the bugs i think happens when the user clicks on the "minus" object i will write here its script) another thing i did, is an overdrive minus, that when the user clicks on a "minus" object it takes back the overdrive bonus one number back.
this is the script:
overdrive bonus (when the user clicks on the target object)

Code: Select all

on UpdateOverDriveClickBonus
   add 1 to _sessionClicks
   add 1 to _sessionClicks2
   set the thumbPosition of scrollbar "ProgressOverDrive" to (_sessionClicks2 - _alreadyDid)
   put CalculateOverDriveBonus() into _overDriveBonus
   put CalculateOverDriveBonus2() into _overDriveBonus2
   if _overDriveBonus2 is an integer
   then
      put "X" & _overDriveBonus2 into field "overDriveBonus"
      ShowBetterOverDrive
   else
   end if
end UpdateOverDriveClickBonus


function CalculateOverDriveBonus2
   return (_sessionClicks / 20 ) +1
end CalculateOverDriveBonus2


function CalculateOverDriveBonus
   return trunc (_sessionClicks / 20 ) +1
end CalculateOverDriveBonus


on ShowBetterOverDrive
   if _overDriveBonus > 1
   then
      --resetta lo scrollbar a 0
      set the thumbPosition of scrollbar "ProgressOverDrive" to 0
      --resetta il numero dei click
      #put empty into _sessionClicks2
      --aggiungi 20 nel variable dei già fatt
      add 20 to _alreadyDid
      --set the size of fld "overDriveBonus" to più grande
      set the textSize of fld "overDriveBonus" to 115
      set the width of fld "overDriveBonus" to 150
      set the height of fld "overDriveBonus" to 130
      set the loc of fld "overDriveBonus" to 160,80
      send RepositionOverDrive to me in 1.5 seconds
   else
   end if
end ShowBetterOverDrive


on RepositionOverDrive
   --resize
   set the textSize of fld "overDriveBonus" to 30
   set the width of fld "overDriveBonus" to 46
   set the height of fld "overDriveBonus" to 31
   --relocate
   set the location of fld "overDriveBonus" to 285,18
end RepositionOverDrive
overdrive minus (when the user clicks on a "minus" object)

Code: Select all

on OverDriveMinus
   if _overDriveBonus2 > 1
   then
      --quelli che si vedranno
      put empty into _sessionClicks2
      put empty into _alreadyDid
      --
      put the thumbPosition of scrollbar "ProgressOverDrive" into tInPiu
      put (_sessionClicks - 20 - tInPiu) into _sessionClicks
      put (_overDriveBonus2 - 1) into _overDriveBonus2
      #if _alreadyDid > 20
      #then
         #put (_alreadyDid - 20) into _alreadyDid
         #set the thumbPosition of scrollbar "ProgressOverDrive" to 0
      else
      end if
   if _overDriveBonus > 1
   then
      put (_overDriveBonus - 1) into _overDriveBonus
      put "X" & _overDriveBonus into field "overDriveBonus"
   else
   end if
   set the thumbPosition of scrollbar "ProgressOverDrive" to 0
end OverDriveMinus
the script of the target object: (the other handlers, i don't think they're relevant)

Code: Select all

local sLocationOf

on mouseDown
   ClickMe
   aeMoveDone
   displayPlus
end mouseDown

on aeMoveDone
   get the location of me
   put it into sLocationOf
end aeMoveDone


on ClickMe
   dispatch UpdateScore with 5
   UpdateOverDriveClickBonus
   HandleBonusObject
end ClickMe


on displayPlus
   show fld "PlusOneHeader"
   set the location of fld "PlusOneHeader" to sLocationOf
   send "HideHeader" to me in 0.25 seconds
end displayPlus


on HideHeader
   hide fld "PlusOneHeader"
end HideHeader
the "minus" object script:

Code: Select all

local sLocationOf

on mouseDown
   ClickMinus100
   aeMoveDone
   displayMinus
   mobileVibrate
end mouseDown


on aeMoveDone
   get the location of me
   put it into sLocationOf
end aeMoveDone


on ClickMinus100
   dispatch UpdateScoreMinuses with -5
   OverDriveMinus
end ClickMinus100


on displayMinus
   show fld "minusHeader"
   set the location of fld "minusHeader" to sLocationOf
   send "HideHeader" to me in 0.2 seconds
end displayMinus


on HideHeader
   hide fld "minusHeader"
end HideHeader
in general this is what the stack should do:
1- when the user clicks on the click me button it adds 5 points to the score
1.5- and it increases the current value of the scrollbar to the appropriate variable

2- when the user clicks on the minus button it subtracts 5 points from the score

3- after the user clicks 20 times consecutively on the click me button the x1 sign becomes x2 and every click of the click me button becomes 10 points (times 2) and so on... (if the sign is x2 it becomes x3 and every click on the click me button becomes 15 points...)

4- if the user clicks on the minus button when the thumbposition of the scrollbar is greater than 1 (in the script i have put this value in a variable), that means the user clicked on the click me button then the thumbposition of the scrollbar will become 0

5- if the user clicks on the minus button when the thumbposition of the scrollbar is 0 (start value) and the sign is greater than 1 (x1) then, the sign will become -1 of the current ( if it is x3 it will become x2 and so on...)

6- when i say 'the sign' i don't mean only the field but also the variable that multiplies the points I think this is in general what the stack should do without going into detail about the variables and the appropriate codes. Thanks!

(if you think there's an easier way to make all this happen the right way please, do tell)
any help would be helpful!
Thanks!

Re: Overdrive Bonus

Posted: Wed Mar 09, 2022 7:45 pm
by Samuele
i re-posted the questions in order here:viewtopic.php?f=7&t=36815

Re: bonus for clicks

Posted: Wed Mar 09, 2022 7:48 pm
by FourthWorld
Duplicate threads merged.

In the future please make only one thread about a given topic, so folks can more easily decide where to post replies, and future readers can find the discussion in one place.