Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Input at ANY time
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TokenHerbz




PostPosted: Sun Sep 04, 2005 8:34 pm   Post subject: 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...

code:

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...

code:

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....
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Sep 04, 2005 8:49 pm   Post subject: (No subject)

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

Turing:

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.

Turing:

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




PostPosted: Mon Sep 05, 2005 4:34 am   Post subject: (No subject)

say i have somthing like

code:

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




PostPosted: Mon Sep 05, 2005 7:47 am   Post subject: (No subject)

tokenherbz wrote:

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.

code:

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]




PostPosted: Mon Sep 05, 2005 11:22 am   Post subject: (No subject)

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:
code:
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




PostPosted: Mon Sep 05, 2005 1:17 pm   Post subject: (No subject)

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]




PostPosted: Mon Sep 05, 2005 1:24 pm   Post subject: (No subject)

Laughing 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




PostPosted: Mon Sep 05, 2005 2:15 pm   Post subject: (No subject)

Gandalf, im still going to use it for now, as it keeps it cleaner...

code:

loop
%%Tells you to pick a choice%%
if ans <= 4 and ans >= 1 then
            ans1 := ans     %%Remembers
            exit
        else
            cls
        end if
    end loop
   
    %%By passes a loop
    if ans >= 1 and ans <= 3 then
        cls
        exit
    end if
    cls


~~~~~~~~~~~~~~
ANYWAYS,

I dont know where to enter the proc?

like you say make the keybored one, which i have done, i make it so it called another proc which i need...

But where do i put it??

This is for an RPG, where i have lots of If, Fors, and loops...

Start it after the main loop?? i tryed...

Also when i have a situation of...

code:

get ans

I dont think i'll be eble to enter the "UP" Arrow key... as its wanting a number... Tell me how to get around that??

Ill zip my up-2-date RPG to you if you want,

Thanks,
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon Sep 05, 2005 2:53 pm   Post subject: (No subject)

Let's look at your concept a little...I'll rephrase that. Let's look at the concept.

- create an RPG-styled game that could viably include various forms of graphics, sounds, and most importantly, interactions.
- said interactions could be evnironmental (objects on screen react to each others' presence, eg. collision detection), textual (messages being displayed), graphical, audible, etc etc.
- an important aspect of this would have to be User-input. This would likely define movement, choice selection, etc.
- there would be several levels of gameplay involved, eg. interactive environment, intereactive menus, fight sequences/interactive fights, cinematics (ok, Turing's not going to do too well here Laughing), etc etc

We can continue to analyze this topic till the cows come home, or the fat lady sings, or the mocking birds get sued, or whatever...but that's actually already been done for us. This rather old Tut will give you a great breakdown and even some hints regarding everything RPG-ish you'll need. I will warn you again that it's old and as such some concepts and command structures used have been outdated (the whole playing music in a process thing comes to mind).

Back to your problem. The entire point of this preramble was to point out an important detail. One that Cervantes (Oh good grief, Canvas!) has already put out there. The use of procedures, records, fucntions, and Object Oriented programming in general. You're really, *really* going to want to make sure you have this stuff down pat if you're serious about making an "extremely awsome" RPG.

Having looked at some of your code you've included, I'd say you're on the right path.
A good strategy I've found when making some sort of programme that involves User input is to have only one area of Input. This sounds familiar doesn't it? Everything in your programme has to react according to the input given, and if you can narrow down your code such that this only occurs in your 'main' procedure, then you're in good standing already.
Since everything that happens then, is a result of the main proc, you'll be in a position that no matter what happens, you'll always end up back in the main proc's loop which will house the Input clause. Did that make sense? It should, it's been said before but not in so many words.

As for the mass of loops, ifs, fors, etc that you'll undoubtedly have, simply ensure that none of them run the risk of falling into infinity and you should be able to return back to the main loop each time. And don't worry, a computer has the ability to get through quite a bit of code and processing and back out in time to catch even the most nimble of fingers' input.

You'll want to stay very far away from any input that pauses for the User (such as get, getch). hasch is a possibility, but doesn't quite stack up against Input.KeyDown().

So, let's look at a little example now, shall we?:

pseudo:

// Yes, this is just pseudo, don't go copying it into your IDE!

proc uselessLetters (inVar : string)
  inVar += "extra letters"
end

proc checkHP (inChar : user_char)
  if inChar.HP < inChar.minHP then
     inChar.status := "dead"
  elsif inChar.status = "healing" then
     inChar.HP += inChar.magik.healEffect
  // and so on and so forth, use your imagination
end

// some more procs and fcns here.  Hey, why not add some modules and classes too!?

// finally:
proc main
  accept_input
  proccess_input
  DO_STUFF // Ha, gotta love those caps
  update_screen
end


Was that useful? Likely not. But go think upon it anyway, perhaps you'll figure out what I'm getting at...
As said before, if you're still not getting anywhere, post some code. I highly doubt that posting your entire proggie is giong to help since that would mean us wading through mountains of code that may or may not be commented enough for us to understand its underlying complexities and meanings and as such be utterly and irrevocably adverse to the said reason of obtaining help from said analysers of said code in said timeframe and I'm listening to a remix of Powerless by Nelly Furtado and it rocks.


BTW Canvas-man! Arrays of procedures?! Methinks you've been spending far too much time in Ruby these days. Good stuff.
Learn something new every day...
[Gandalf]




PostPosted: Mon Sep 05, 2005 3:29 pm   Post subject: (No subject)

Been doing a bit o- C, Delos? Smile "IDE" "//" Sure, it's "pseudo", but...

An idea is (if your code is indeed getting cluttered), to have many files for your program. Not just for 'data' and then 'program', but having a seperate file for 'input' 'battles' 'collision detection?', etc. That way, you can then have a 'main' file, with your main loop - simply to have the basic structure of the program. It makes it easier to think everything through and see what your program is doing without going through hundreds of lines of code.

You cannot 'get' the up arrow, that is what Input.KeyDown is used for.

Making an RPG is no simple matter, so expect problems.

Quote:
BTW Canvas-man! Arrays of procedures?! Methinks you've been spending far too much time in Ruby these days. Good stuff.
Learn something new every day...

Same Smile, I agree.
Cervantes




PostPosted: Mon Sep 05, 2005 5:34 pm   Post subject: (No subject)

tokenherbz wrote:

I dont know where to enter the proc?

like you say make the keybored one, which i have done, i make it so it called another proc which i need...

But where do i put it??

Somewhere in your main loop, preferrably in the 'Input' section. I like to break my main loop up, if possible, into 'Input', 'Processing', and 'Output' sections.

[Gandalf] wrote:

Been doing a bit o- C, Delos? Smile "IDE" "//" Sure, it's "pseudo", but...

"IDE" and "//" are not specific to C. Java, for example, uses "//" as a one-line comment. Also, I'm sure that almost every language has at least one IDE.

Delos wrote:
BTW Canvas-man! Arrays of procedures?! Methinks you've been spending far too much time in Ruby these days. Good stuff.
Learn something new every day...

One can never spend too much time with Ruby. Smile
I did not invent that, however; I reinvented it and then rediscovered that that is how Turing's GUI works.
ButtonClass:

var userActionProc : procedure actionProc ()

That's what prevents you from linking procedures with parameters to your buttons. That's the greatest annoyance of Turing's GUI.

tockemhaerbx wrote:

thanks for the help Canvas (sorry itf i spelled wrong)

Exclamation
+10 BITS for calling me something that ridiculous!

EDIT: Arrgh! Dan still hasn't fixed the donating/modding bits. I owe you ten bits, tokenherbz. That reminds me: I owe someone else bits, though I forget who and how much.
[Gandalf]




PostPosted: Mon Sep 05, 2005 5:46 pm   Post subject: (No subject)

Yes, yes... Bits all around!

Quote:
"IDE" and "//" are not specific to C. Java, for example, uses "//" as a one-line comment. Also, I'm sure that almost every language has at least one IDE.

I am quite aware of that, I was just taking a guess since those two examples are things not used in Turing. Personally, I wouldn't call the Turing, eh... Environment an IDE (I know that is a slight contradiction, but you know what I mean).
Delos




PostPosted: Mon Sep 05, 2005 9:53 pm   Post subject: (No subject)

Nope, no O'C for me, or C for that matter. Just a lot of Turing when time permits. As I always say, I should really get into Ruby.
As for the whole mod-bit-thing, [cue British accent]what's all this then?[/accent]
wtd




PostPosted: Mon Sep 05, 2005 10:35 pm   Post subject: (No subject)

Delos wrote:
Nope, no O'C for me


Well, that's a shame. Objective-C is kinda cool.
TokenHerbz




PostPosted: Tue Sep 06, 2005 2:06 am   Post subject: (No subject)

Heh, My code i think is more then enough Commented...

Or so to me anyways...

Im going to post my RPG anyways, so you can take a look at my mess...

You will then see how i think its utterly impossible to call my proc at ANY GIVIN POINT!

Here it is, and yes, You can play what is made, not that i am far...



RPG.zip
 Description:
Here it is, try playing it aswell,
Its my 1st! -but its pretty sweet.

Download
 Filename:  RPG.zip
 Filesize:  5.42 KB
 Downloaded:  119 Time(s)

Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 22 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: