Hi,
I expect this is another newbie question, but here goes...
I'm trying to set up a counter in a script whose target can be set using a variable rather than a constant. For example:
set 'counter' 0 &
set 'count_max' 4 &
repeat_start 'RScounting' 33ms 10 &
var_list &
param_bigger "get_var'counter'" "get_var'count_max'" ?
repeat_stop 'RScounting' :
get_var 'counter' & param_add 1 & param_cast & set 'counter'
I want 'counter' to increment until it reaches 'count_max' then stop. As my example stands, 'counter' increments 10 times until it reaches the hard limit that I set in the "repeat_start 'RScounting' 33ms 10" line. The "param_bigger" condition (as I've written it) is never met. I have also tried using - cycle 'counter' "get_var'count_max'" - but that doesn't seem to work either.
I want to use a variable rather than a constant so that I can set various key values in a larger script which are based on a variable which is initially set once only.
I will be very grateful for any help :-)
Domino
Posté Sat 11 Jan 20 @ 1:17 pm
yours is missing spaces between get_var and the name
repeat_start 'RScounting' 33ms 10 & var_list & param_bigger "get_var 'counter'" "get_var 'count_max'" ? repeat_stop 'RScounting' : get_var 'counter' & param_add 1 & param_cast & set 'counter'
*Edit param_bigger looks backwards
get_var 'a' & param_bigger "get_var 'b'" ?
=
is a bigger than b
param_bigger "get_var 'a'" "get_var 'b'" ?
=
is b bigger than a
I think you also want equal and not bigger, and since it's vars, var_equal/greater/smaller can be written shorter with just the name
repeat_start 'RScounting' 33ms 10 & var_list & var_equal 'counter' 'count_max' ? repeat_stop 'RScounting' : get_var 'counter' & param_add 1 & param_cast & set 'counter'
using cycle won't work as is because when counter is about to hit countermax it will tick over back to zero you could however
get_var 'counter_max' & param_add 1 & param_cast 'integer' & cycle 'counter'
you also count up like this [although looks like 'counter' needs to be initialised to zero before the rsi]
set 'counter' `get_var 'counter' & param_add 1`
*edit after Adion's advice
this works without the fuss though
set 'counter' `param_add "get_var 'counter'" 1`
repeat_start 'RScounting' 33ms 10 & var_list & param_bigger "get_var 'counter'" "get_var 'count_max'" ? repeat_stop 'RScounting' : get_var 'counter' & param_add 1 & param_cast & set 'counter'
*Edit param_bigger looks backwards
get_var 'a' & param_bigger "get_var 'b'" ?
=
is a bigger than b
param_bigger "get_var 'a'" "get_var 'b'" ?
=
is b bigger than a
I think you also want equal and not bigger, and since it's vars, var_equal/greater/smaller can be written shorter with just the name
repeat_start 'RScounting' 33ms 10 & var_list & var_equal 'counter' 'count_max' ? repeat_stop 'RScounting' : get_var 'counter' & param_add 1 & param_cast & set 'counter'
using cycle won't work as is because when counter is about to hit countermax it will tick over back to zero you could however
get_var 'counter_max' & param_add 1 & param_cast 'integer' & cycle 'counter'
you also count up like this [although looks like 'counter' needs to be initialised to zero before the rsi]
set 'counter' `get_var 'counter' & param_add 1`
*edit after Adion's advice
this works without the fuss though
set 'counter' `param_add "get_var 'counter'" 1`
Posté Sat 11 Jan 20 @ 1:48 pm
repeat_start will increment forever if no repeat count or -1 is specified
CYCLE VARIABLE within SPECIFIC RANGE or VARIABLE BOUNDS:
increment:
set 'd' "`get_var 'd' & param_add 1 & param_greater 'get_decks' ? get_constant 1 `"
decrement:
set 'd' "`get_var 'd' & param_add -1 & param_equal 0 ? get_decks`"
in your case:
repeat_start 'RScounting' 33ms -1 &
var_list &
cycle 'counter' 2147483647 &
param_smaller "get_var 'counter'" "get_var 'count_max'" ?
repeat_stop 'RScounting' : nothing
CYCLE VARIABLE within SPECIFIC RANGE or VARIABLE BOUNDS:
increment:
set 'd' "`get_var 'd' & param_add 1 & param_greater 'get_decks' ? get_constant 1 `"
decrement:
set 'd' "`get_var 'd' & param_add -1 & param_equal 0 ? get_decks`"
in your case:
repeat_start 'RScounting' 33ms -1 &
var_list &
cycle 'counter' 2147483647 &
param_smaller "get_var 'counter'" "get_var 'count_max'" ?
repeat_stop 'RScounting' : nothing
Posté Sat 11 Jan 20 @ 1:48 pm
I would recommend to use the 2 parameter variant of param_add btw:
param_add 1 `get_var 'd'`
param_add 1 `get_var 'd'`
Posté Sat 11 Jan 20 @ 2:57 pm
Adion's advice & locodog notice, use the 2 parameter variant & param_add as well as param_greater do not need backquotes to execute actions
help and allow things like this:
set 'd' `param_add 1 'get_var d' & param_greater 'get_decks' ? get_constant 1 `
set 'd' `param_add -1 'get_var d' & param_equal 0 ? get_decks`
this allows to pre-compute the iteration count
set 'counter' 0 &
set 'count_max' 4 &
param_add "get_var count_max" "param_multiply -1 'get_var counter' " &
repeat_start 'RScounting' 33ms & set 'counter' `param_add "get_var counter" 1`
help and allow things like this:
set 'd' `param_add 1 'get_var d' & param_greater 'get_decks' ? get_constant 1 `
set 'd' `param_add -1 'get_var d' & param_equal 0 ? get_decks`
this allows to pre-compute the iteration count
set 'counter' 0 &
set 'count_max' 4 &
param_add "get_var count_max" "param_multiply -1 'get_var counter' " &
repeat_start 'RScounting' 33ms & set 'counter' `param_add "get_var counter" 1`
Posté Sat 11 Jan 20 @ 6:14 pm