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

Username:   Password: 
 RegisterRegister   
 Copy Paste Code Only Works First Time
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
Warchamp7




PostPosted: Tue Sep 09, 2008 8:30 am   Post subject: Copy Paste Code Only Works First Time

Alright so basically I'm adding some slight horizontal "acceleration" to my game and it works perfectly on the title screen. However, when I copy/pasted the code into my main game section, it does not work.

I'm very confused by this, why would it work in one block of code but not another?

Added some comments in %% for forums
Turing:
%Horizontal "Gravity"
    if velx > RunSpeed then
        velx := RunSpeed %%Caps the run speed
    elsif velx < -RunSpeed then
        velx := -RunSpeed
    end if
   
    if velx > 0 and velx < 6.5 then
        if velx < 2 then %%Slightly slower acceleration when under 2
            velx := velx - .10
        else
        velx := velx - .20
        end if
    elsif velx < 0 and velx > -6.5 then
        if velx > -2 then
            velx := velx + .10
        else
            velx := velx + .20
        end if
    end if
 
Sponsor
Sponsor
Sponsor
sponsor
apomb




PostPosted: Tue Sep 09, 2008 8:55 am   Post subject: RE:Copy Paste Code Only Works First Time

you're using variables multiple times without changing the default values back. the objects will already be positioned incorrectly.
 
Warchamp7




PostPosted: Tue Sep 09, 2008 10:53 am   Post subject: Re: RE:Copy Paste Code Only Works First Time

apomb @ Tue Sep 09, 2008 8:55 am wrote:
you're using variables multiple times without changing the default values back. the objects will already be positioned incorrectly.


RunSpeed is a constant so it stays at its default.

velx is the horizontal velocity which gets reset before every level.
 
Tony




PostPosted: Tue Sep 09, 2008 11:21 am   Post subject: Re: Copy Paste Code Only Works First Time

Warchamp7 @ Tue Sep 09, 2008 8:30 am wrote:
when I copy/pasted the code into my main game section, it does not work.

Well there's your problem.

apomb already pointed out that there's more to this than just the posted block of code. If you find yourself copy/pasting blocks of logic, then you are doing it wrong. Encapsulate this into a function.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
 
Warchamp7




PostPosted: Tue Sep 09, 2008 12:56 pm   Post subject: Re: Copy Paste Code Only Works First Time

Tony @ Tue Sep 09, 2008 11:21 am wrote:
Warchamp7 @ Tue Sep 09, 2008 8:30 am wrote:
when I copy/pasted the code into my main game section, it does not work.

Well there's your problem.

apomb already pointed out that there's more to this than just the posted block of code. If you find yourself copy/pasting blocks of logic, then you are doing it wrong. Encapsulate this into a function.


Yeah, I found my problem and I feel rather dumb. I had forgotten that I had to modify the key controls for this and had not done so to the main games controls.

As for functions, I've never used them before, gonna do some reading up.

Yay for logic errors Mr. Green
 
isaiahk9




PostPosted: Wed Oct 08, 2008 5:09 pm   Post subject: RE:Copy Paste Code Only Works First Time

this may be off topic, I'm thoroughly impressed if you came up with the idea for this code (acceleration).
 
[Gandalf]




PostPosted: Wed Oct 08, 2008 6:53 pm   Post subject: RE:Copy Paste Code Only Works First Time

isaiahk9, it's been a month since the last post, stop necro posting with useless comments.
 
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: