Posted: 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
endif
Posted: 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
Posted: 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
Posted: 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.
Posted: 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
isaiahk9
Posted: 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]
Posted: 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.