Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Function Error

Author
Message
luma
13
Years of Service
User Offline
Joined: 8th Mar 2011
Location: Porto, Portugal
Posted: 9th Mar 2011 00:05
Hi,

I'm new on this and i have a problem with a function that a cant figure it out.

I have this function that creates a ball every time the main loop do a pass.

this function have a n=1 before the loop and a n=n+1 inside the loop after a call the function ball(n).
And i have the following error - The name 'ball' duplicated in the program at line 276.

any ideas about what is wrong?

tyvm
luma
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 9th Mar 2011 11:24
Could you post the rest of your code? I can't immediately see from this what the problem is although someone else might be able to.
luma
13
Years of Service
User Offline
Joined: 8th Mar 2011
Location: Porto, Portugal
Posted: 9th Mar 2011 11:53
Sure, here:



here is the thing. All I want is to have a function that substitutes an old for/next:

with a function it will be more handy to build levels and so on.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 9th Mar 2011 16:37 Edited at: 9th Mar 2011 16:39
First off, your program runs into a function. Place all functions at the end of your code.

I would suggest that you create an additional function that will give you a unique object number every time. You will need a global variable to track it. Use
near the start of your code and code the function:


From within your do -loop, the call is made like this:


This way, you know that you will never create the same object twice. You should use the GetFreeObject() function for all of your objects in the game, not just the ones for your ball(n) function.

EDIT: Bear in mind that you will need to store the ball numbers in some way so that you can recall them for checking position, collision, etc. I would use TYPE variables myself, but you could use an array also.

luma
13
Years of Service
User Offline
Joined: 8th Mar 2011
Location: Porto, Portugal
Posted: 12th Mar 2011 16:38
Well i get the same error but now with the "GetFreeObject":
The name 'GetFreeObject' duplicated in the program at line 297.

Is there anything out of its place?

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 12th Mar 2011 17:55 Edited at: 13th Mar 2011 13:17
Here is how you can use it effectively:


EDIT: I would note that I consider using GOTO a poor programming practice, but I left it in, as it is your program and not mine. I would suggest writing a subroutine that handles when a player dies and another subroutine when the game is to be restarted.

Login to post a reply

Server time is: 2024-11-16 20:01:27
Your offset time is: 2024-11-16 20:01:27