
-----------------------------------
PHP God
Mon Apr 21, 2003 6:07 pm

My Newbish Game
-----------------------------------
I'm making a game where the user is prompted to select a character then select some starting coordinates and use the WSAD keys to move it around. Here is my code thus far (note it is not complete)


% The Moving Program

%%%%%%%%%%%%%%%%%%%%%%%
%      Variables      %
%%%%%%%%%%%%%%%%%%%%%%%

var moveChar:string (1)

var dirSel:string (1)

var winStatus:int:=Window.Open ("fullscreen")

var yesOrNo:string (1)

var xStart:int
var yStart:int

var anyKey:string (1)

%%%%%%%%%%%%%%%%%%%%%%%
%      Procedures     %
%%%%%%%%%%%%%%%%%%%%%%%

procedure moveUp
 if xStart=1
  then sound (1000,100)
 elsif xStart=maxrow
  then sound (1000,100)
 end if
 xStart:= xStart+1
end moveUp

%procedure moveDown

%procedure moveLeft

%procedure moveRight

%%%%%%%%%%%%%%%%%%%%%%%
%       Program       %
%%%%%%%%%%%%%%%%%%%%%%%

loop

put "There are ",maxrow," rows on this screen."
put "There are ",maxcol," columns on this screen."
put ""
put "You can chose a character and move it anywhere in these boundaries with this program."
put ""
put "Select You Character :: "..
 getch (moveChar)
cls

loop
put "You have chosen to use ",moveChar,"."
put ""
put "Is this correct? (Y/N) :: "..
 getch (yesOrNo)
  if yesOrNo = "y" then
   exit
  elsif yesOrNo = "n" then
   exit
  else put ""
       put "Invalid Input"
  end if
  
  cls
  end loop
 if yesOrNo = "y"
  then exit
 end if
 cls
end loop

loop
cls
 put "Choose the starting coordinates for your character"
 put ""
  loop
   put "Choose an x value between 1 and ",maxrow,"."
    get xStart
     if xStart > maxrow then
      put "Value is too high"
      put ""
     elsif xStart < 1 then
      put "Value is too low"
      put ""
     else exit
     end if
  end loop
  loop
 put ""
 put "Choose a y value between 1 and ",maxcol,"."
  get yStart
       if yStart > maxcol then
      put "Value is too high"
      put ""
     elsif yStart < 1 then
      put "Value is too low"
      put ""
     else exit
     end if
  end loop
  exit
end loop

setscreen ("nocursor")
cls

put ""
put " CONTROLS"
put " ==============="
put " W - Move Up"
put " S - Move Down"
put " A - Move Left"
put " D - Move Right"
put ""
put " X - Quit"
put ""
put " Press Any Key To Start The Game..."
 getch (anyKey)
 
cls

loop
 cls
  locate (xStart,yStart)
  put moveChar
 getch (dirSel)
  if dirSel = "w"
   then moveUp
  elsif dirSel = "s"
   then moveDown
  elsif dirSel = "a"
   then moveLeft
  elsif dirSel = "d"
   then moveRight
  elsif dirSel = "x"
   then exit
end loop


If you will examine the code at the very bottom


  if dirSel = "w"
   then moveUp
  elsif dirSel = "s"
   then moveDown
  elsif dirSel = "a"
   then moveLeft
  elsif dirSel = "d"
   then moveRight


You will see I have used if statements and depending on input, I am trying to call a procedure. when I try to run my program, it says that moveUp and all the others are not declared, well. At the top I declared moveUp and I'm stuck.

How do you call a procedure after a THEN statement?

-----------------------------------
Tony
Mon Apr 21, 2003 6:13 pm


-----------------------------------
you'd have to read a tutorial on procedures and fuctions, it might help out with examples.

a quick guess is that procedures need to have parameters, even if you dont pass any values to it. Such as

procedure something()
put "blah"
end something


notice that () in the procedure name. You might need to have it. Check tutorial for examples, its the best way to find errors - compare to working code

-----------------------------------
Catalyst
Mon Apr 21, 2003 6:47 pm


-----------------------------------
no, you dont need to do that in turing (ur prob thinking of c++)
you can have something like

procedure move
put "Hello"
end move

ne way the the only errors i get r concerning the other move procs not moveUp

also turing may have caught this  but

procedure moveUp 

if xStart=1 
  then sound (1000,100) 
elsif xStart=maxrow 
  then sound (1000,100) 
end if

is never ended

it shoudl be more like


procedure moveUp 

if xStart=1 
  then sound (1000,100) 
elsif xStart=maxrow 
  then sound (1000,100) 
end if
end moveUp

[/code]

-----------------------------------
Tony
Mon Apr 21, 2003 7:01 pm


-----------------------------------
ah yes... since you commented other procedures out, turing doesnt know what to call.

also it seems you dont have "end if" in there

-----------------------------------
Prince
Mon Apr 21, 2003 7:07 pm


-----------------------------------
its cus u hav the procedures moveDown, moveLeft and moveRight as comments (wit the % in front)... plus ders no code for it to b run in the first place :?

-----------------------------------
Prince
Mon Apr 21, 2003 7:08 pm


-----------------------------------
nuts, u wer too quick for me tony :( ... lol

-----------------------------------
PHP God
Mon Apr 21, 2003 8:23 pm


-----------------------------------
I know some are comments but moveUp isn't so it should work. my question was just in case you are illiterate, how do i call a procedure after a then statement?

-----------------------------------
Tony
Mon Apr 21, 2003 8:32 pm


-----------------------------------
just put its name there :?


procedure hi
put "hi"
end hi

hi %