Posted: Sat Oct 15, 2011 9:24 pm Post subject: RE:Boolean and if statement help
oh ok thanks!!!!!!!!!!!
my teachers a bit picky about where you put the code but if he puts up a fuss then Ill just show him the Turing Walkthrough whatchyamacallit thingy lol "aka my new best friend" haha
Sponsor Sponsor
Tony
Posted: Sat Oct 15, 2011 9:32 pm Post subject: RE:Boolean and if statement help
Well your code should be organized in some way that makes sense. As one of my profs said:
Quote:
If you write clean code, your TAs will not get as angry reading it, and will be less likely to give you bad grades.
Posted: Sun Oct 16, 2011 10:01 am Post subject: RE:Boolean and if statement help
my computer blocks the Turing reference thing so thats why i couldnt check that
Insectoid
Posted: Sun Oct 16, 2011 11:25 am Post subject: RE:Boolean and if statement help
procedure is an actual procedure. If you don't know what a procedure is, you probably shouldn't be touching buttons yet. Stick to a text interface for now imo.
sammi
Posted: Sun Oct 16, 2011 11:39 am Post subject: Re: RE:Boolean and if statement help
Insectoid @ Sun Oct 16, 2011 11:25 am wrote:
procedure is an actual procedure. If you don't know what a procedure is, you probably shouldn't be touching buttons yet. Stick to a text interface for now imo.
i know what a procedure is but i just wasnt sure if i had to sustitute it
Sponsor Sponsor
Aange10
Posted: Sun Oct 16, 2011 11:42 am Post subject: RE:Boolean and if statement help
sammi wrote:
i know what a procedure is but i just wasnt sure if i had to sustitute it
Experiment
sammi
Posted: Sun Oct 16, 2011 12:03 pm Post subject: RE:Boolean and if statement help
do you guys mind if i post my code again and ask you a few things?
sammi
Posted: Sun Oct 16, 2011 12:07 pm Post subject: Re: RE:Boolean and if statement help
sammi @ Sun Oct 16, 2011 12:03 pm wrote:
do you guys mind if i post my code again and ask you a few things?
never mind, i figured it out
sammi
Posted: Sun Oct 16, 2011 12:59 pm Post subject: RE:Boolean and if statement help
So here my code so far. it has a few problems (mentioned underneath the code)
do u mind helping me?
import GUI
%%% WHAT I WANT THE BUTTON TO DO WHEN I CLICK IT%%%
procedure NextQuestionMenu
put "Ask the magic 8 ball another question"
end NextQuestionMenu
procedure ExitGame
put " Awww you can't tell me your done already....."
end ExitGame
%% DECLARING MY VARIABLES %%
var Question : string %the typing cursor
var Answer : int % part of the array
var valid : boolean := true %number check
var words : array 1 .. 11 of string %the answers
%var Mouse.Where(350, 50, YesButton)
%% PARTS OF THE ARRAY %%
words (1) := "Yes"
words (2) := "No"
words (3) := "Maybe"
words (4) := "Thats for me to know and you to find out "
words (5) := "Of course"
words (6) := "I doubt it"
words (7) := "In your dreams"
words (8) := "Keep dreaming"
words (9) := "How the heck am i suppossed to know?"
words (10) := "Obviously"
words (11) := "Absolutely"
%% PROGRAM%%%%%
loop
% Asking the question
locatexy (200, 390)
put "Ask the Magic 8-Ball a question"
% drawing the ball
Draw.FillOval (330, 250, 100, 100, brightred)
% Getting a response
locatexy (250, 250)
get Question : *
% Make sure the question contains no numbers
for i : 1 .. length (Question) % Represents the Character of the string
for b : 1 .. 9 % checks to see if the character, i, has a number.
if Question (i) = intstr(b) then % If it does, it sets valid to false.
valid := false % if it finds a number then it recognizes an improper question
cls()
exit
end if
end for
end for
locatexy (200, 100) % position of answer and "invalid" comment
if valid then
Answer := Rand.Int (1, 11)
put words (Answer)
else
locatexy (200, 220)
put "Thats not a question silly!!!"
delay (1500)
cls()
end if
locatexy (200, 20)
put "Would you like to ask another question?"
var YesButton : int:= GUI.CreateButton (250, 50, 0, "Yes", NextQuestionMenu)
var NoButton : int:= GUI.CreateButton (350, 50, 0, "No", ExitGame)
exit when GUI.ProcessEvent
end loop
PROBLEMS: When they enter a non valid question (numbers), it does exactly what i want it to. But when they enter a valid question then the answer pops up but so does "thats not a question silly" which i only want for invalid questions.
Aange10
Posted: Sun Oct 16, 2011 2:10 pm Post subject: RE:Boolean and if statement help
To put your code in a syntax (Like we all did ours) use (syntax="turing") and (/syntax) to quit ... But don't use ()'s use []'s ... It makes it much much easier to read....
But, looking at your coding, there are a few things you need to do... If they ask an invalid question, what happens to our valid variable? It turns it false... When they ask their next question, did it reset the value?
Turing:
valid :=true% Reset the question value
Secondly, you're drawling the buttons, forking the program, and then continuing back to the beginning. (Forking the program is where you make it do two things at once... sorta.) ... So the program never stops to wait for you to hit a button, it just draws them and continues on. The buttons "work", but not until your program gets back to them.
It's a bit complicated, but your solution would look like
Turing:
put"Would you like to ask another question?" loop var YesButton :int:=GUI.CreateButton(250, 50, 0, "Yes", NextQuestionMenu) var NoButton :int:=GUI.CreateButton(350, 50, 0, "No", ExitGame) exitwhenGUI.ProcessEvent endloop
.... Now, you're program does exactly what you told it to do.
sammi
Posted: Sun Oct 16, 2011 2:57 pm Post subject: RE:Boolean and if statement help
okay but when i click it it just draws the buttons over and over again
Aange10
Posted: Sun Oct 16, 2011 3:17 pm Post subject: Re: RE:Boolean and if statement help
sammi @ 16/10/2011, 1:57 pm wrote:
okay but when i click it it just draws the buttons over and over again