
-----------------------------------
starcraft
Sat May 27, 2006 11:21 am

turing choice
-----------------------------------
Im trying to create a numbers choices into a "chain". This is what I have so far. 




setscreen ("graphics:v256")
setscreen ("graphics:640,480")


%Set variable choice.
var choice: string
var choice2: string
var leave: string


%OUTPUT TITLE
%Set variable and font.
var font : int
font := Font.New ("timesroman:30")
        var height, ascent, descent, internalLeading : int
        Draw.Text ("Title Page", 10, 280, font, green)
        Draw.Text ("Choose 1 or 2:", 10, 240, font, green)
        %Add anything else you want to the title page.
 
        
%SET UP CONSTRUCT FOR OUTPUT OF CHOICE 1 OR 2.
%Set the prompt at x,y.         
locatexy(270,250)
get choice:*

%Clear screen.
cls
    
    %Set up if/elsif/else contruct for output.
    if choice = "1" then
        put "You choose 1. Hit 'enter' to exit!" 
        locatexy(280,480)
        get choice2:*
        
     elsif choice="2" then
        put"You choose 2. Hit 'enter' to exit!" 
        locatexy(280,480)
        get choice2:*
     else
        %When the answer to the condition is not one of the choices, the execution
        %transfers here.
        put "Try Again"
    
    end if
    




var font2 : int
font2 := Font.New ("timesroman:30")
        var height2, ascent2, descent2, internalLeading2 : int
        Draw.Text ("Title Page", 10, 280, font2, brightred)
        Draw.Text ("Choose 1 or 2:", 10, 240, font2, brightred)
 

%Set the prompt at x,y.         
locatexy(270,250)
get choice2:*

%Clear screen.
cls
    
    %Set up if/elsif/else contruct for output.
    if choice2 = "1" then
        put "You choose 1. Hit 'enter' to exit!" 
        locatexy(280,480)
        get choice:*
        
     elsif choice="2" then
        put"You choose 2. Hit 'enter' to exit!" 
        locatexy(280,480)
        get leave:*
     else
        %When the answer to the condition is not one of the choices, the execution
       %transfers here.
        put "Try Again"
    
    end if
    
%OUTPUT END STATEMENT
%--------------------------------------------------------------------
cls
%Output end statement.
locatexy(200,300)
put"The end."

-----------------------------------
starcraft
Sat May 27, 2006 11:27 am


-----------------------------------
this just let you to acces a title page, got to one choice selection, and then goto another choice selection, then the end page.

Im trying to figure out, like would it be possible to go to choice2, then come back to choice 1 from choice 2, without accessing the end page. 

I tried to change the,


if choice2 = "1" then
        %Drawn out outputs here including moving object for first choice.
        put "You choose 1. Hit 'enter' to exit!" 
        locatexy(280,480)
        get choice:*
        
     elsif choice="2" then
        %Drawn out outputs here including moving object for first choice.
        put"You choose 2. Hit 'enter' to exit!" 
        locatexy(280,480)
        get leave:*


the get leave to get choice, but it doesn't work, can someone help out?

-----------------------------------
jamonathin
Sat May 27, 2006 1:14 pm


-----------------------------------
First and foremost, please use code tags.[code] {Put Code Here} [/code]

Secondly, welcome to the forums.  Now what you're going to want to do is learn loops - you can go to the Turing Walkthrough and there will be a tutorial for you in there.

Your coding is setup in a linear manner, meaning it runs from top to bottom and that's it.


Here is a quick example:

var choice : int %Our variable

loop
    cls
    put "Enter your choice (0 exits): " ..
    get choice  %Getting choice
    exit when choice = 0 %Telling loop to end when choice = 0
    cls
    put "You have selected choice ", choice, "!"
    put "\n Press Any Key to Continue"
    Input.Pause %Wait's for an input to continue
end loop


Everything in the loop keeps going over and over (looping) until CHOICE = 0.  Loop's are fairly easy to work with once you understand them, just read up that loop tutorial and you should do fine :).

-----------------------------------
Clayton
Sat May 27, 2006 7:08 pm


-----------------------------------
actually another (no offense jamon) is to use procedures (procs) these are little compartments of code that you can call on from your main line and are very useful in reducing redundant code, check the Turing Walkthrough for the tut on them :D

-----------------------------------
starcraft
Sat May 27, 2006 8:44 pm


-----------------------------------
thx, because I'm try to create pacman using this method, So it's like you move down 1 square, you hit S key, move up you hit W key. etc, So it's just like a huge chain of choices.

-----------------------------------
HellblazerX
Sun May 28, 2006 3:53 pm


-----------------------------------
If you're using that for keyboard input, then you might as well use the Input.KeyDown method.  There's a nice tutorial for it [URL=http://www.compsci.ca/v2/viewtopic.php?t=114]here.
