my math game script

repeat -- loop
	-- gets the random numbers
	set x to [random number from 0 to 100]
	set y to [random number from 0 to 100]
	set d to "+"
	set e to "="
	-- gets the answer as text 
	set o to [x + y] as text
	-- asks for the answer
	set dialogResult to display dialog ¬
		(x as text) & (d) & (y as text) default answer " "
	-- if right displays well dun and ask to continuo
	if [text returned of dialogResult is o] then
		display dialog "well dun " buttons {"end", "continuo?"} default button 2
		if the button returned of the result is "continuo?" then
			
		else
			exit repeat
		end if
	else
		-- if wrong displays the sum whit the answer and asks to end or to continuo
		display dialog (x as text) & (d) & (y as text) & (e) & (o) buttons {"continuo?", "end"} default button 2
		if the button returned of the result is "continuo?" then
			
		else
			exit repeat
		end if
		
	end if
end repeat

hope u all like it :smiley:

Some more fun :slight_smile:

property OPERATORS : "+-*"
property MAX_RANDOM : 100

repeat
	set o to some character of OPERATORS
	set a to random number from 0 to MAX_RANDOM
	set b to random number from 0 to MAX_RANDOM
	set r to run script (a as text) & o & b
	
	set u to text returned of (display dialog (a as text) & space & o & space & b & " = ..." default answer "")
	
	if (u as string) is (r as string) then
		display dialog "Well done!" buttons {"Cancel", "Continue"} cancel button 1 default button 2
	else
		display dialog "Oh!!" & return & a & space & o & space & b & " = " & r buttons {"Cancel", "Continue"} cancel button 1 default button 2
	end if
end repeat

thanks i dint know about property OPERATORS : “±*” but now i do thanks

May;

There is no AppleScript word or property called “OPERATORS”. Lef has defined a string with that variable name and then chosen one character from the string at random in the repeat loop. He could have done the same with a list: set OPERATORS to {“+”, “-”, “*”}, but that’s a lot more typing than the string he used.

The clever bit of his script is that he builds a new string: (a as text) & o & b and then runs it as a script fragment: set r to run script text_fragment_here. You can make a list like that too:

set list_string to "1, 2, 3, 4"
set L to run script "{" & list_string & "}"
L --> {1, 2, 3, 4}

Hi.

Square brackets (‘[’ and ‘]’) are used in AppleScript to represent a certain kind of list which hasn’t been supported for over thirteen years (ie. since before I started!). They shouldn’t be used in place of parentheses ” or at all.

ok well i am only a grad 10 student and in our computer class at school we learn EXL so i don’t know what i am doing rely
thats y i jonde this site thanks for the tip