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

Username:   Password: 
 RegisterRegister   
 How to change controls for a game.....
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
amz_best




PostPosted: Tue Sep 09, 2014 8:27 pm   Post subject: How to change controls for a game.....

What is it you are trying to achieve?
The ability to change controls in a game

for example:

Turing:

Input.KeyDown (blah)
     if (KEY_BLAH) then
       blah = true
      end if

%to something like

Input.KeyDown (blah)
    if (Button chosen) then
        blah = true
    end if


What is the problem you are having?
I HAVE ABSOLUTELY NO IDEA HOW TO ACHIEVE IT.


Describe what you have tried to solve this problem
N/A


Please specify what version of Turing you are using
Open turing 1.0
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Sep 09, 2014 9:11 pm   Post subject: RE:How to change controls for a game.....

Oh, you must have some idea... you are half way there!
code:

Input.KeyDown (blah)
     if (KEY_BLAH) then
       blah = true
      end if


What's the type and value of KEY_BLAH?

Reading through documentation is typically the first step to understanding what's going on -- Input.KeyDown
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
amz_best




PostPosted: Tue Sep 09, 2014 9:38 pm   Post subject: RE:How to change controls for a game.....

^Not exactly, i've already gotten dat far xD
what im looking for is a way to change (key_blah) to something else, like in a game, you change the moving up button to "w" instead of "KEY_UP_ARROW", YEAH, i wasnt clear... but dat is wat im looking for
ofcourse, while code is running, without closnig and re changing code...
Tony




PostPosted: Wed Sep 10, 2014 1:19 am   Post subject: RE:How to change controls for a game.....

KEY_UP_ARROW is a constant, which has some value.
code:

put KEY_UP_ARROW
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
amz_best




PostPosted: Wed Sep 10, 2014 10:11 am   Post subject: Re: How to change controls for a game.....

Turing:


var UAK : string :=  KEY_UP_ARROW
var control : array char of boolean

put "Up arrow key?"..
get UAK


loop
Input.KeyDown (control)

if control (UAK) then
Draw.FillBox (0, 0, maxx, maxy, black)
end if
end loop






^This code will not work...


i need an idea of a way to change the CONTROL of moving a player to something else without closing turing and reprogramming.
Dreadnought




PostPosted: Wed Sep 10, 2014 10:15 pm   Post subject: Re: How to change controls for a game.....

What is the type of UAK?
Can you use that type for the index of an array?
amz_best




PostPosted: Sat Sep 13, 2014 6:35 pm   Post subject: RE:How to change controls for a game.....

i am fairly new sir... and i can say... idk wtf u just said. But i found something out about these "ch" and "char" variables and i might be able 2 get it working!
Dreadnought




PostPosted: Sat Sep 13, 2014 9:38 pm   Post subject: Re: How to change controls for a game.....

So Input.KeyDown will give you an array indexed (the index is the position of a value in the array) by characters (hence the "char") where each entry is either true of false (indicating whether or not a key is down).

The reason we can use characters to index an array is because they are actually represented as numbers by the machine (see the ord function).

You have the right idea in the code above; get a character from the user that will correspond to "UP" and check if it is pressed. The issue is that you are getting a string from the user.

A string is a sequence of characters (to the machine it's just an array of characters). But we can't use a string for the position of something (what position would "hello" have?) instead we want to get a single character.
This is where we use the char type you found. It is a single character.

Let's try changing that string to a char:
Turing:
var UAK : char := KEY_UP_ARROW
var control : array char of boolean

put "Up arrow key?" ..
%UAK := getchar()
get UAK


loop
    Input.KeyDown (control)

    if control (UAK) then
        Draw.FillBox (0, 0, maxx, maxy, black)
    end if
end loop


Hey it works! kinda....
When we hit a key (like the up arrow) the key we pressed is printed (for the up arrow it prints E with an acute accent) and then we have to press ENTER. You might say "Bah, I can work with this", but we can do better.

Enter the Input.getchar function. It gives you a single character the user inputs.

Here's a little example:
Turing:
loop
    var ch : char
    ch := Input.getchar ()

    % Wait a bit so we don't spam the window
    Time.Delay (50)

    put "You entered:", ch
end loop


Hopefully this is more helpful than my previous post.
Sponsor
Sponsor
Sponsor
sponsor
amz_best




PostPosted: Fri Sep 19, 2014 7:11 pm   Post subject: RE:How to change controls for a game.....

Turing:

%-Declare vars-%
%--------------------------------
var y : int := 100              %
var gottenCH: boolean:= false   %
var ch : char                   %
%--------------------------------

loop

    %get only a button
    if gottenCH = false then
    put "Enter Move Circle Up: "..
    ch := Input.getchar ()
    gottenCH := true
    end if
   
   
    Time.Delay (50) 
    drawoval (100, y, 100, 100, blue)
   
    %i didnt think dis would work lol
    if ch = Input.getchar () then
    y += 1
    end if
   
end loop




EDIT: I GOT IT 2 WORK XD yay lol but i idk how to make it moar than 1 char... BTW, i used ur code and made it work for only 1 button, but i need moar "1 buttons"....
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 1  [ 9 Posts ]
Jump to:   


Style:  
Search: