F
F Tom
Guest
As the title says, how do you check if some given number is a square root of some other number?
I am creating a kind of crafting system where player/user can specify the size of the crafting field. The crafting field must be 3x3, 4x4 etc. It can't be for example 2x5. So the program gets the number of cells and it should check if dimensions are valid. It can be any number (in some normal ranges, not some crazy ones) such as 9, 36, 100 etc.There's a sqrt function. Calculate the square root of a number using that, compare it to some other number and check if they're equal.
var sr = sqrt(yourNumber)
if(sr == floor(sr))
//do something
cra_w = clamp(cra_w, min_w, max_w);
cra_h = clamp(cra_h, min_h, max_h);
if (cra_w > cra_h) {
cra_w = cra_h;
}
else if (cra_h > cra_w) {
cra_h = cra_w;
}
if (cra_w == cra_h) {
if (cra_w == clamp(cra_w, min_w, max_w) && cra_h == clamp(cra_h, min_h, max_h)) {
//Continue
}
}
else {
//Terminate and ask for a re-input
}
//scr_init
globalvar tableSizes;
tableSizes = scr_array_create(50); // 50x50 max f.e.
var i;
for (i=1;i< array_length_1d(tableSizes)+1;i++) {
tableSizes[i-1] = sqr(i); // Fill array with squares
}
//where it's used
recipeHolder = split(recipe,",");
recipeLen = array_length_1d(recipeHolder);
if scr_array_find(tableSizes,recipeLen) = "-7"{
return "#Error, invalid recipe format"; // Square root not whole number
}