IDk why but I my game crashes and sometimes dose not do what its suppose to

Can someone take a look at my code and tell if what I am doing wrong

on enter do
say "Welcome to Single Player, Press A on a dot to place an X"
Box1 = 0
Box2 = 0
Box3 = 0
Box4 = 0
Box5 = 0
Box6 = 0
Box7 = 0
Box8 = 0
Box9 = 0
end

on place do
if event.px==12 then
if event.py==9 then
if Box8==0 then
Box8 = 1
tell 12,9 to
swap "TileX"
end
tell event.room to
call "win"
call "aiturn"
end
end
end
if event.py==7 then
if Box5==0 then
Box5 = 1
tell 12,7 to
swap "TileX"
end
tell event.room to
call "win"
call "aiturn"
end
end
end
if event.py==5 then
if Box2==0 then
Box2 = 1
tell 12,5 to
swap "TileX"
end
tell event.room to
call "win"
call "aiturn"
end
end
end
end

if event.px==10 then

	if event.py==9 then
		if Box7==0 then
			Box7 = 1
			tell 10,9 to
				swap "TileX"
			end
			tell event.room to
				call "win"
				call "aiturn"
			end
		end
	end
	
	if event.py==7 then
		if Box4==0 then
			Box4 = 1
			tell 10,7 to
				swap "TileX"
			end
			tell event.room to
				call "win"
				call "aiturn"
			end
		end
	end
	
	if event.py==5 then
		if Box1==0 then
			Box1 = 1
			tell 10,5 to
				swap "TileX"
			end
			tell event.room to
				call "win"
				call "aiturn"
			end
		end
	end
	
end

if event.px==14 then
	if event.py==9 then
		if Box9==0 then
			Box9 = 1
			tell 14,9 to
				swap "TileX"
			end
			tell event.room to
				call "win"
				call "aiturn"
			end
		end
	end
	
	if event.py==7 then
		if Box6==0 then
			Box6 = 1
			tell 14,7 to
				swap "TileX"
			end
			tell event.room to
				call "win"
				call "aiturn"
			end
		end
	end
	
	if event.py==5 then
		if Box3==0 then
			Box3 = 1
			tell 14,5 to
				swap "TileX"
			end
			tell event.room to
				call "win"
				call "aiturn"
			end
		end
	end
end

end

on aiturn do
aipick = random 1,9

if aipick==1 then
	if Box1==0 then
		Box1 = 2
		tell 10,5 to
			swap "TileO"
		end
		tell event.room to
			call "win"
		end
	elseif Box1>0 then
		tell event.room to
			call "aiturn"
		end
	end
end

if aipick==2 then
	if Box2==0 then
		Box2 = 2
		tell 12,5 to
			swap "TileO"
		end
		tell event.room to
			call "win"
		end
	elseif Box2>0 then
		tell event.room to
			call "aiturn"
		end
	end
end

if aipick==3 then
	if Box3==0 then
		Box3 = 2
		tell 14,5 to
			swap "TileO"
		end
		tell event.room to
			call "win"
		end
	elseif Box3>0 then
		tell event.room to
			call "aiturn"
		end
	end
end

if aipick==4 then
	if Box4==0 then
		Box4 = 2
		tell 10,7 to
			swap "TileO"
			
		end
		tell event.room to
			call "win"
		end
	elseif Box4>0 then
		tell event.room to
			call "aiturn"
		end
	end
end

if aipick==5 then
	if Box5==0 then
		Box5 = 2
		tell 12,7 to
			swap "TileO"
			
		end
		tell event.room to
			call "win"
		end
	elseif Box5>0 then
		tell event.room to
			call "aiturn"
		end
	end
end

if aipick==6 then
	if Box6==0 then
		Box6 = 2
		tell 14,7 to
			swap "TileO"
			
		end
		tell event.room to
			call "win"
		end
	elseif Box6>0 then
		tell event.room to
			call "aiturn"
		end
	end
end


if aipick==7 then
	if Box7==0 then
		Box7 = 2
		tell 10,9 to
			swap "TileO"
			
		end
		tell event.room to
			call "win"
		end
	elseif Box7>0 then
		tell event.room to
			call "aiturn"
		end
	end
end

if aipick==8 then
	if Box8==0 then
		Box8 = 2
		tell 12,9 to
			swap "TileO"
			
		end
		tell event.room to
			call "win"
		end
	elseif Box8>0 then
		tell event.room to
			call "aiturn"
		end
	end
end


if aipick==9 then
	if Box9==0 then
		Box9 = 2
		tell 14,9 to
			swap "TileO"
			
		end
		tell event.room to
			call "win"
		end
	elseif Box9>0 then
		tell event.room to
			call "aiturn"
		end
	end
end

end

on win do
if Box1==1 then
if Box2==1 then
if Box3==1 then
say "Player 1 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win1"
end
else
tell event.room to
call "win1"
end
end
elseif Box1==2 then
if Box2==2 then
if Box3==2 then
say "Player 2 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win1"
end
else
tell event.room to
call "win1"
end

	end
else
	tell event.room to
		call "win1"
	end
end

end

on win1 do
if Box6==1 then
if Box5==1 then
if Box4==1 then
say "Player 1 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win2"
end
else
tell event.room to
call "win2"
end
end
elseif Box6==2 then
if Box5==2 then
if Box4==2 then
say "Player 2 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win2"
end
else
tell event.room to
call "win2"
end

	end
else
	tell event.room to
		call "win2"
	end
end

end

on win2 do
if Box7==1 then
if Box8==1 then
if Box9==1 then
say "Player 1 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win3"
end
else
tell event.room to
call "win3"
end
end
elseif Box7==2 then
if Box8==2 then
if Box9==2 then
say "Player 2 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win3"
end
else
tell event.room to
call "win3"
end

	end
else
	tell event.room to
		call "win3"
	end
end

end

on win3 do
if Box2==1 then
if Box5==1 then
if Box7==1 then
say "Player 1 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win4"
end
else
tell event.room to
call "win4"
end
end
elseif Box2==2 then
if Box5==2 then
if Box7==2 then
say "Player 2 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win4"
end
else
tell event.room to
call "win4"
end

	end
else
	tell event.room to
		call "win4"
	end
end

end

on win4 do
if Box3==1 then
if Box6==1 then
if Box9==1 then
say "Player 1 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win5"
end
else
tell event.room to
call "win5"
end
end
elseif Box3==2 then
if Box6==2 then
if Box9==2 then
say "Player 2 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win5"
end
else
tell event.room to
call "win5"
end

	end
else
	tell event.room to
		call "win5"
	end
end

end

on win5 do
if Box4==1 then
if Box1==1 then
if Box7==1 then
say "Player 1 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win6"
end
else
tell event.room to
call "win6"
end
end
elseif Box4==2 then
if Box1==2 then
if Box7==2 then
say "Player 2 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win6"
end
else
tell event.room to
call "win6"
end

	end
else
	tell event.room to
		call "win6"
	end
end

end

on win6 do
if Box5==1 then
if Box3==1 then
if Box7==1 then
say "Player 1 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win7"
end
else
tell event.room to
call "win7"
end
end
elseif Box5==2 then
if Box3==2 then
if Box7==2 then
say "Player 2 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win7"
end
else
tell event.room to
call "win7"
end

	end
else
	tell event.room to
		call "win7"
	end
end

end

on win7 do
if Box9==1 then
if Box5==1 then
if Box1==1 then
say "Player 1 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win8"
end
else
tell event.room to
call "win8"
end
end
elseif Box9==2 then
if Box5==2 then
if Box1==2 then
say "Player 2 Wins"
tell event.room to
call "reset"
end
end
else
tell event.room to
call "win8"
end
else
tell event.room to
call "win8"
end

	end
else
	tell event.room to
		call "win8"
	end
end

end

on win8 do
if Box1>0 then
if Box2>0 then
if Box3>0 then
if Box4>0 then
if Box5>0 then
if Box6>0 then
if Box7>0 then
if Box8>0 then
if Box9>0 then
say "Its a Draw"
tell event.room to
call "reset"
end
end
end
end
end
end
end
end
end
end
end

on reset do
tell event.room to
tell 10,5 to
swap "dot1"
end
tell 12,5 to
swap "dot1"
end
tell 14,5 to
swap "dot1"
end
tell 10,7 to
swap "dot1"
end
tell 12,7 to
swap "dot1"
end
tell 14,7 to
swap "dot1"
end
tell 10,9 to
swap "dot1"
end
tell 12,9 to
swap "dot1"
end
tell 14,9 to
swap "dot1"
end
end
goto 12,12 in "Main Menu"

end

changed my AI to elseif

Hello, and welcome to the pulp forum! The project looks very interesting, but it's a bit tricky to help with the post as it is above - if I may, I'd suggest making some edits to make it easier for others:

  • Explain what you're trying to do (and a screenshot can be very helpful)
  • Explain what's not working, and what it should do
  • Use the "Preformatted text" option in the post editor for all your code, and try to indent your nested code blocks (anything ending with an end) - I usually just use ``` to start and end code blocks
  • If adding extra info, say if that's fixed it or if you're still looking for help

Hope it's coming along well though! Let us know if you're still stuck, and I'm sure the community will help out as much as possible. Looking forward to seeing the end result :slight_smile: