
-----------------------------------
wolfdeity
Mon May 12, 2014 8:34 pm

strint not ok
-----------------------------------
I am new to programing in turring and I'm trying to make a custom dice roller app that first asks the user how many dice the user wants followed by the amount of sides the die has.
since I don't want the program to crash when the user accidentally inputs a non-numeric input I used  the strintok command.
the problem is that this makes me have to put all of the error messages at the end of the code because of the way that the else then statments are which is making it very dificult to debug the code 
does anyone have anyway I could put the error message before the rest of the code?
%simple dice
%May 12 2014 

loop
locate (1,1)
    %sets the variables
    var input : string
    var in2 : string
    var i : int
    var final : int
    var c : int
    %ask for total dice
  loop 
        put "How many dice are you rolling?"
    get input
        if strintok (input) 
     then
        c:= strint (input)
     
else
    put "That is not a number, try again."
 end if

    end loop
   
      
         %asks for total sides
    put "How many sides does the die have?"
loop
      get in2
        if strintok (in2) then
        i:= strint (in2)
    else 
         put "That is not a number, try again?"

    %roll's die
        put "Rolling..."
     for counter : 1 .. c %counts down how many dice to roll
    randint (final, 1, i)
      put final
    %outputs
    if final = i
            then
        put "Critical Hit"
    end if
        if final = 1
                then
            put "Critical Miss"
        end if
            %Ending Cleanup
    
    delay (100)
   end for
   put"###################################" %makes for cleaner seperation
     end if
   end loop
 

-----------------------------------
keyboardwalker
Mon May 12, 2014 9:33 pm

RE:strint not ok
-----------------------------------
I think what you're looking for is not.
If you not the original condition then
the logic is reversed and the cases
can be switched.
A section of an if is executed
when then condition above it is true. 
if the condition becomes not strintok
then it should execute the error
(the first case, so it's easier "to debug")

Example:

if 
a
else
b
end if

will do the exact same as:

if 
b
else
a
end if

in Turing syntax it would be something like

if x = y then
a
else
b
end if

will do the exact same as:

if not x = y then
b
else
a
end if

The operator is, "not" or the 'shorthand', "~" will also do what you want.
