Page 1 of 2
integer
Posted: Thu Jan 27, 2022 5:20 pm
by Samuele
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!!
Re: integer
Posted: Thu Jan 27, 2022 5:31 pm
by Klaus
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
...
Re: integer
Posted: Thu Jan 27, 2022 5:39 pm
by Samuele
Klaus wrote: ↑Thu Jan 27, 2022 5:31 pm
Or do you mean:
yes, i meant that, but it won't work

Re: integer
Posted: Thu Jan 27, 2022 5:40 pm
by Klaus
"won't work" is a very bad error description!
Please show your script or whatever you tried...
Re: integer
Posted: Thu Jan 27, 2022 5:42 pm
by Samuele
Klaus wrote: ↑Thu Jan 27, 2022 5:40 pm
"won't work" is a very bad error description!
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.
Re: integer
Posted: Thu Jan 27, 2022 5:49 pm
by Klaus
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!
Re: integer
Posted: Thu Jan 27, 2022 5:54 pm
by richmond62
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.
Re: integer
Posted: Thu Jan 27, 2022 5:55 pm
by Samuele
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)
Re: integer
Posted: Thu Jan 27, 2022 5:57 pm
by dunbarx
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
Re: integer
Posted: Thu Jan 27, 2022 5:57 pm
by Klaus
Of course I meant "where you want to check" in your SCRIPT!
Re: integer
Posted: Thu Jan 27, 2022 5:58 pm
by Samuele
richmond62 wrote: ↑Thu Jan 27, 2022 5:54 pm
SShot 2022-01-27 at 18.26.59.png
the zip file is empty
Re: integer
Posted: Thu Jan 27, 2022 6:00 pm
by richmond62
Whoops . . . I wonder how that happened.
Re: integer
Posted: Thu Jan 27, 2022 6:03 pm
by Samuele
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
Re: integer
Posted: Thu Jan 27, 2022 6:09 pm
by Klaus
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...
Re: integer
Posted: Thu Jan 27, 2022 6:19 pm
by Samuele
alright, i figured i'd share only the inherent parts of my stack: