
-----------------------------------
Warchamp7
Tue Sep 09, 2008 8:30 am

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
%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

-----------------------------------
apomb
Tue Sep 09, 2008 8:55 am

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
Tue Sep 09, 2008 10:53 am

Re: 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.

RunSpeed is a constant so it stays at its default.

velx is the horizontal velocity which gets reset before every level.

-----------------------------------
Tony
Tue Sep 09, 2008 11:21 am

Re: Copy Paste Code Only Works First Time
-----------------------------------
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.

-----------------------------------
Warchamp7
Tue Sep 09, 2008 12:56 pm

Re: Copy Paste Code Only Works First Time
-----------------------------------
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  :mrgreen:

-----------------------------------
isaiahk9
Wed Oct 08, 2008 5:09 pm

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]
Wed Oct 08, 2008 6:53 pm

RE:Copy Paste Code Only Works First Time
-----------------------------------
isaiahk9, it's been a month since the last post, stop necro posting with useless comments.
