bonus for clicks

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

Post Reply
Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Overdrive Bonus

Post by Samuele » Wed Feb 09, 2022 10:08 pm

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!
Samuele.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Overdrive Bonus

Post by dunbarx » Thu Feb 10, 2022 5:58 am

Hard for me to get going with your issue with only the handlers. Post the stack.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Overdrive Bonus

Post by richmond62 » Thu Feb 10, 2022 9:21 am

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
Attachments
CLICKER.livecode.zip
Stack.
(1.09 KiB) Downloaded 79 times

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Overdrive Bonus

Post by Klaus » Thu Feb 10, 2022 11:37 am

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

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: Overdrive Bonus

Post by Samuele » Sat Feb 12, 2022 9:01 pm

alright, that's the stack:
clickMe.zip
(6.69 KiB) Downloaded 81 times
Thanks!
Samuele.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Overdrive Bonus

Post by richmond62 » Sun Feb 13, 2022 10:20 am

Great functionality, but:
-
SShot 2022-02-13 at 11.18.27.png

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Overdrive Bonus

Post by dunbarx » 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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Overdrive Bonus

Post by richmond62 » Mon Feb 14, 2022 8:58 am

I have a lot of questions . . .
-
SShot 2022-02-14 at 9.56.08.png

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: Overdrive Bonus

Post by Samuele » Wed Feb 16, 2022 4:51 pm

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!
Last edited by Samuele on Wed Feb 16, 2022 6:07 pm, edited 2 times in total.
Samuele.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Overdrive Bonus

Post by dunbarx » 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

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: Overdrive Bonus

Post by Samuele » Tue Mar 01, 2022 11:46 am

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? 👆
Samuele.

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

bonus for clicks

Post by Samuele » Wed Mar 09, 2022 7:43 pm

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!
Samuele.

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: Overdrive Bonus

Post by Samuele » Wed Mar 09, 2022 7:45 pm

i re-posted the questions in order here:viewtopic.php?f=7&t=36815
Samuele.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: bonus for clicks

Post by FourthWorld » Wed Mar 09, 2022 7:48 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”