integer

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

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

integer

Post by Samuele » Thu Jan 27, 2022 5:20 pm

Hi, how can i say in livecode words a number that is not decimal, for example 2, 6, 8 but not 1.5, 3.7...
i tried with

Code: Select all

 if _someVariable is an integer then
but it didn't work.
more specifically, I'm trying to make a 'PointsMultiplier' that will be resized when a variable is a 'complete number'

Code: Select all

on UpdateOverDriveClickBonus
   add 1 to _sessionClicks
   set the thumbPosition of scrollbar "ProgressOverDrive" to _sessionClicks
   put CalculateOverDriveBonus() into _overDriveBonus
   put "X" & _overDriveBonus into field "overDriveBonus"
   ShowBetterOverDrive
end UpdateOverDriveClickBonus



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


on ShowBetterOverDrive
   if _overDriveBonus is an integer and _overDriveBonus > 1
   then
      --resetta lo scrollbar a 0
      set the thumbPosition of scrollbar "ProgressOverDrive" to 0
      set the location of fld "overDriveBonus" to 160, 80
      --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
      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
any ideas?
i've found another problem, after the first time that ShowBetterOverDrive runs (when _sessionClicks becomes greater than 1) the progress bar will be always full because it's set to be the value of _sessionClicks , and that's a problem.
so basically this code works until _sessionClicks beacomes greater than 1, then nothing works properly
any other ideas?
thanks!!
Samuele.

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

Re: integer

Post by Klaus » Thu Jan 27, 2022 5:31 pm

Maybe you mean "round()?

Code: Select all

...
put round(1.5)
## -> 2
put round(1.4)
## -> 1
...
Or do you mean:

Code: Select all

...
if your_number_here contains "." then
  ## it is afloating point number
else
  ## it is a "whole" integer
end if
...

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

Re: integer

Post by Samuele » Thu Jan 27, 2022 5:39 pm

Klaus wrote:
Thu Jan 27, 2022 5:31 pm
Or do you mean:
yes, i meant that, but it won't work :?
Samuele.

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

Re: integer

Post by Klaus » Thu Jan 27, 2022 5:40 pm

"won't work" is a very bad error description! 8)
Please show your script or whatever you tried...

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

Re: integer

Post by Samuele » Thu Jan 27, 2022 5:42 pm

Klaus wrote:
Thu Jan 27, 2022 5:40 pm
"won't work" is a very bad error description! 8)
Please show your script or whatever you tried...
Samuele wrote:
Thu Jan 27, 2022 5:20 pm
Hi, how can i say in livecode words a number that is not decimal, for example 2, 6, 8 but not 1.5, 3.7...
i tried with

Code: Select all

 if _someVariable is an integer then
but it didn't work.
more specifically, I'm trying to make a 'PointsMultiplier' that will be resized when a variable is a 'complete number'

Code: Select all

on UpdateOverDriveClickBonus
   add 1 to _sessionClicks
   set the thumbPosition of scrollbar "ProgressOverDrive" to _sessionClicks
   put CalculateOverDriveBonus() into _overDriveBonus
   put "X" & _overDriveBonus into field "overDriveBonus"
   ShowBetterOverDrive
end UpdateOverDriveClickBonus



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


on ShowBetterOverDrive
   if _overDriveBonus is an integer and _overDriveBonus > 1
   then
      --resetta lo scrollbar a 0
      set the thumbPosition of scrollbar "ProgressOverDrive" to 0
      set the location of fld "overDriveBonus" to 160, 80
      --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
      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
any ideas?
i've found another problem, after the first time that ShowBetterOverDrive runs (when _sessionClicks becomes greater than 1) the progress bar will be always full because it's set to be the value of _sessionClicks , and that's a problem.
so basically this code works until _sessionClicks beacomes greater than 1, then nothing works properly
any other ideas?
thanks!!
that's my script (i 've edited the question, maybe you answered before i edited)
i tried instead of "is an integer"

Code: Select all

on ShowBetterOverDrive
   if _overDriveBonus contains "." and _overDriveBonus > 1
   then...
this code didn't run, so i think that _sessionClicks never becamed a "whole" number but that's strange, beacause when _sessionClicks becomes a number divisible by 20 then in theory _overDriveBonus should be a "whole" number.
Samuele.

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

Re: integer

Post by Klaus » Thu Jan 27, 2022 5:49 pm

Yes, I saw the script but have no idea where you want to "hook"?
we do not know the rest of your app and the context of this script.
Is it this line:

Code: Select all

set the thumbPosition of scrollbar "ProgressOverDrive" to _sessionClicks
?
What did you set as "endvalue" for the progressbar?

Please explain where you want to check for integer/floating point number!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: integer

Post by richmond62 » Thu Jan 27, 2022 5:54 pm

SShot 2022-01-27 at 18.26.59.png

Code: Select all

on mouseUp
   put fld "ff" into XX
   if XX is an integer then
      put "INTEGER" into fld "gg"
   else
      put "NO WAY!" into fld "gg"
   end if
end mouseUp
Stack deleted and reposted lower down.
Last edited by richmond62 on Thu Jan 27, 2022 6:01 pm, edited 1 time in total.

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

Re: integer

Post by Samuele » Thu Jan 27, 2022 5:55 pm

Klaus wrote:
Thu Jan 27, 2022 5:49 pm
What did you set as "endvalue" for the progressbar?
20,
Klaus wrote:
Thu Jan 27, 2022 5:49 pm
Please explain where you want to check for integer/floating point number!
i don't mind when it checks it (but as a matter of fact, now it checks it every time the user clicks on a button)
Samuele.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: integer

Post by dunbarx » Thu Jan 27, 2022 5:57 pm

Hi.

The use of "is an integer" does all it says it does. You do not need anything else. Works with negative, positive numbers and zero.

Setting a thumbPosition to a floating point number does not throw an error. LC will just set the position to the nearest integer.

What is the error that LC displays?

Craig

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

Re: integer

Post by Klaus » Thu Jan 27, 2022 5:57 pm

Of course I meant "where you want to check" in your SCRIPT!

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

Re: integer

Post by Samuele » Thu Jan 27, 2022 5:58 pm

richmond62 wrote:
Thu Jan 27, 2022 5:54 pm
SShot 2022-01-27 at 18.26.59.png
the zip file is empty
Samuele.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: integer

Post by richmond62 » Thu Jan 27, 2022 6:00 pm

Whoops . . . I wonder how that happened.
Attachments
INTEGER.livecode.zip
Here's the stack.
(1019 Bytes) Downloaded 124 times

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

Re: integer

Post by Samuele » Thu Jan 27, 2022 6:03 pm

dunbarx wrote:
Thu Jan 27, 2022 5:57 pm
Hi.

The use of "is an integer" does all it says it does. You do not need anything else. Works with negative, positive numbers and zero.

Setting a thumbPosition to a floating point number does not throw an error. LC will just set the position to the nearest integer.

What is the error that LC displays?

Craig
there's no error, it's just it does not do what it's supposed to do, when the _sessionClicks is a number non divisible by 20 (8/20 = 0.4) the code

Code: Select all

if _overDriveBonus is an integer then #do something
does the do something anyway
Samuele.

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

Re: integer

Post by Klaus » Thu Jan 27, 2022 6:09 pm

That is really strange, LC does a good job when checking for integers!?
put (1.5 is an integer) -> FALSE
put (1.0 is an integer) -> TRUE

So the problem must be somewhere else...

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

Re: integer

Post by Samuele » Thu Jan 27, 2022 6:19 pm

alright, i figured i'd share only the inherent parts of my stack:
OverDriveBonus.zip
(1.53 KiB) Downloaded 131 times
Samuele.

Post Reply