Hey y’all! I was struggling to find a way to identify strings vs. integers, and couldn’t find any solutions already up, so after racking my brain I came up with a subroutine. If anyone ever comes up with a similar issue, here’s my solution:
*create result false
(code and stuff here)
*label is_num
*params target
*temp length length(target)
*temp pointer 0
*temp count 0
*temp found_dot false
*temp found_negative false
*set result false
*if (target#1) = "-"
*if length > 1
*set pointer +1
*set found_negative true
*goto is_loop
*set result false
*return
*label is_loop
*set count 0
*set pointer +1
*if (target#pointer) = "."
*if found_dot = false
*if found_negative
*if (pointer < length) and (pointer > 2)
*set pointer+1
*set found_dot true
*goto is_result_loop
*if found_negative = false
*if (pointer < length) and (pointer > 1)
*set pointer+1
*set found_dot true
*goto is_result_loop
*set result false
*return
*label num_chk
*if count <= 9
*if (target#pointer) = count
*goto is_result_loop
*set count+1
*goto num_chk
*set result false
*return
*label is_result_loop
*if pointer < length
*goto is_loop
*set result true
*return
It’s pretty intuitive, despite how the code looks. Basically, it just runs through the inputed variable and checks each character to see if it’s 0-9, and keeps track of “-” or “.” to account for negatives and decimals. To call it, just run:
*gosub_scene (scene where you put it) is_num (your variable)
And it should return true if it’s an integer, false if it’s anything else. Anyways, tell me if you come across any bugs or mistakes so I can fix it before it breaks my code anyone else’s code.