
-----------------------------------
TokenHerbz
Sun Sep 04, 2005 8:34 pm

Input at ANY time
-----------------------------------
Hi, im making an extremly awsome RPG...

I would like to add a freature to see your STATS at any givin time in the game...

I decided a proc would be wise...


proc stats()
    var winID3 : int
        winID3 := Window.Open ("Graphics:200;200")
        put "Hero: ",player.name
        put "Level: ",player.lvl, "    Exp: ",player.xp
        put ""
        put "Health: ",player.HP
        put "Strength: ",player.strong, " + ", (player.lvl * 3)
        put "Magic: ",player.mana, " + ", (player.lvl * 4)
        put "Money: $",money
        Input.Pause
        Window.Close (winID3)
end stats

This works fine, But i tryed to make it so when you press the UP arrow key of works...

This DOSN"T work, i need help...

What code do i place to GET this proc??

i attempted this...


var keys: array char of boolean

*at the START of my code*
Input.KeyDown (keys)

if keys (KEY_UP_ARROW) then
    stats()
end if


i guess i was thinking if i pressed UP it would call my proc, But NOPE@!

Anyways, i would love help, and please tell me theres an easyer way then having to put it in EACH loop...  As im going to have a FEW procs....

-----------------------------------
Cervantes
Sun Sep 04, 2005 8:49 pm


-----------------------------------
Make sure the declaration of the keys variable is outside your loops; make sure the Input.KeyDown is inside your loop; make sure the if keys (KEY_UP_ARROW) is inside your loop.

If you don't want to put it in each loop, the easiest thing to do would be to make a procedure to handle all the controls.  You might want to think about passing the status of the keyboard into this procedure as a parameter.

If you cannot solve the problem with this, attach your code.

EDIT:
Here's some example code as to how to map out your keyboard and give each key an action.  I've commented out my first attempt at doing this, which is a little more understandable because it does not use 


proc B
    put "Buzzing Bee."
end B

proc C
    put "See"
end C

type Control :
    record
        key : char
        action : procedure p
    end record

var controls : array 1 .. 2 of Control
controls (1).key := KEY_CTRL
controls (1).action := B
controls (2).key := 'z'
controls (2).action := C

var keys : array char of boolean

loop
    Input.KeyDown (keys)
    for i : 1 .. upper (controls)
        if keys (controls (i).key) then
            controls (i).action
        end if
    end for
end loop


But it isn't very nice having to assign two variables just to get one key working.  The following code is more elegant and maps the entire keyboard, at the cost of having to check the boolean status of every key each time through the loop, as opposed to just checking the boolean status of the keys that have an action associated with them, as the previous code did.


proc Do_Nothing
end Do_Nothing

proc B
    put "Buzzing Bee."
end B

proc C
    put "See"
end C

var controls : array char of procedure p

% Initialize the keyboard to do nothing
for i : char
    controls (i) := Do_Nothing
end for
controls (KEY_CTRL) := B
controls ('z') := C

var keys : array char of boolean

loop
    Input.KeyDown (keys)
    for i : char
        if keys (i) then
            controls (i)
        end if
    end for
end loop


-----------------------------------
TokenHerbz
Mon Sep 05, 2005 4:34 am


-----------------------------------
say i have somthing like


loop
      loop
            put "hi"
            put "press 1 to go back"
            get ans
            if ans = 1 then
                  exit
            else
                   cls
            end if
       end loop
       loop
             put "Hello"
             put "press 2 to go back"
             get ans
             if ans = 2 then
                   exit
             else
                   end if
              end if
       end loop
end loop


Now that has 2 loops...

Say i have this...

proc ha
       put "HAHAHA"
end ha

How can i make it so, it i press "UP" no matter WHERE i am in the code,
It WILL work... and post HAHAHA

Thanks...

Also, if your post already told me, please do explain it better, cause you lost me...  thanks

-----------------------------------
Cervantes
Mon Sep 05, 2005 7:47 am


-----------------------------------

How can i make it so, it i press "UP" no matter WHERE i am in the code,
It WILL work... and post HAHAHA 

There is no way to write some code that will automatically stick itself inside every one of your loops.  As I said before, write a procedure to handle all your controls, and call that procedure where ever you want it.


procedure Handle_Controls (keyboard : array char of boolean)
    if keyboard (KEY_UP_ARROW) then
        ha  % Call the 'ha' procedure
    end if
    % Handle other controls in a similar manner.
end Handle_Controls


-----------------------------------
[Gandalf]
Mon Sep 05, 2005 11:22 am


-----------------------------------
Yes, any you might want to use a function to do the 'number checking', since if you are going to be having more than one you could automate the process (although in your case you do so little that it would make a small difference).

Also, why do you have those else statements?  They are pretty pointless, you can write an 'if' statement without including 'else'.  For example, this:
if ans = 2 then
                   exit
             else
                   end if
              end if 
is a syntax error, since you have an end if without a matching 'if'.

-----------------------------------
TokenHerbz
Mon Sep 05, 2005 1:17 pm


-----------------------------------
gandof i tryed to make an exaplme really fast...

it was to be cls

thanks for the help Canvas (sorry itf i spelled wrong)

i will try it...

-----------------------------------
[Gandalf]
Mon Sep 05, 2005 1:24 pm


-----------------------------------
:lol: It's not gandof, it's Gandalf, and it's not Canvas it's Cervantes.

Either way, the 'else' is not needed.  Since the if statement will be evaluated, and if it is true then the loop will exit at that point, if it is not then it will continue, and 'cls'.  It's just a waste of code.

-----------------------------------
TokenHerbz
Mon Sep 05, 2005 2:15 pm


-----------------------------------
Gandalf, im still going to use it for now, as it keeps it cleaner...


loop
%%Tells you to pick a choice%%
if ans = 1 then
            ans1 := ans     %%Remembers
            exit
        else
            cls
        end if
    end loop
    
    %%By passes a loop
    if ans >= 1 and ans 