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 / problem with arrays

Author
Message
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 17th Apr 2010 23:40
Hi, guys! I have a serious problem. I attempted to improve the code below for controling the velocity of Bullets but I just got the strange alert: "Array does not exist or array subscript out of bounds". I don't see reason for that. Anybody, please, could help me?

Attachments

Login to view attachments
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 17th Apr 2010 23:48
sorry my english...
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 17th Apr 2010 23:54
I have other simplier form but is not so clear and I think resolution of this can be enough.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 18th Apr 2010 00:45 Edited at: 18th Apr 2010 00:46
I think the problem is in this type of condition check:



Even though you say "if N=1", it still has to check the rest of the conditions on the line even if N isn't equal to 1. It doesn't just stop. That means that when your FOR/NEXT loop eventually reaches "MaxBullets", the condition looks like this:

if N=1 and FiredBullet(MaxBullets+1)=1 and BulletPosY(MaxBullets+1)=395 and BulletPosY(MaxBullets)>375

There is a problem here, because you only made your arrays hold "MaxBullets" slots!


So when it tries to check slot "MaxBullets+1", that slot doesn't actually exist, which is why you are getting an error.


On a side note, that code looks awfully complicated . What are you trying to do exactly? Maybe there's a simpler way to do it?

<-- Spell based team dueling game!
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 18th Apr 2010 01:28
very thanks for your answer Sixty Squares!! I'm going to analize your tip.

This code is for choose the speed that you want of the bullets, because the original code that I acquired, doesn't:

instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 18th Apr 2010 01:43
Quote: "On a side note, that code looks awfully complicated"


actually the code principal is this, that is further complicated:



He still has a bug that I still can not solve, but I believe the resolution of the simplest code will give me a light
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 18th Apr 2010 03:47
I managed to solve the problem with your tip Sixty Squares, isolating the first condition (N= ), but unfortunately, the same bug (overlap of a bullet to the other) that is present in the code smaller and more complex, also remains in this code. If you have any idea how to fix it, very grateful.

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 18th Apr 2010 06:14
No problem . I am still very confused by your code (so many if/else statements!), but I think I get what the purpose of it was. Was it meant to make sure you can't shoot all of the bullets at once, and to make sure that there is a delay between bullet shootings? I tried shortening your code by a lot and just adding a new variable called ShootDelay that counts down until the next time you can shoot. This way the bullets don't all shoot out at once. After each shot ShootDelay gets set to 100 and you can't shoot again until it reaches 0.

I also got rid of your SLEEP command and added SYNC RATE to control the screen refresh rate instead. Changing the SYNC RATE will change the maximum number of FRAMES PER SECOND you can get in your game. Setting it to 0 will make the game run as quickly as your computer will allow it to.

Anyway, here's the changed code...



Also, about the overlap issue, I think it's just a thing with 2D sprites. Try playing around with SET SPRITE PRIORITY a little bit if you want certain sprites to appear on top of other ones. And if this wasn't what you were talking about then nevermind

<-- Spell based team dueling game!
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 18th Apr 2010 08:23 Edited at: 18th Apr 2010 09:05
LOL I feel ashamed for making up something so simple into something so complicated. True Programming is really for a few ones and you are privileged. very very thanks same, by the code, and by open my eyes to seek the simplicity first.


about the sleep command, I would replace it for sync as you did, but only after getting control of the speed of shots.

Note: The entire code is not mine, I just wanted to improve it.
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 18th Apr 2010 09:38
Quote: "Also, about the overlap issue, I think it's just a thing with 2D sprites. Try playing around with SET SPRITE PRIORITY a little bit if you want certain sprites to appear on top of other ones. And if this wasn't what you were talking about then nevermind"


The way I had tried:



There was a bug that was the real reason for requesting help, what happened when, in trying to fire a shot immediately when the first(just the number one bullet) disappeared of screen, this overlapped it.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Apr 2010 14:36
With regards to shooting multiple bullets, I think you'll find the basic principles in tutorial 11 here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

No disrespect, but why don't you do it properly and learn to program yourself?

Apart from the lack of indentation which makes that code so difficult to follow I just couldn't be bothered looking at it properly, it also contains some very basic errors.

BulletPosY(N)=BulletPosY(N)-0.2

What do you think this is actually doing? And how is it different from:

BulletPosY(N)=BulletPosY(N)-1

My guess is that you (and the original coder to be honest) don't actually know. That's the problem with learning from other people's code - they pass on bad programming habits and you as the beginner don't know it's happening.

If you learnt to program yourself, you wouldn't need to 'adapt' code written by other people.

I also assume that shortcutting the learning process, you won't even understand the answers we give you to your problems.

Please believe me when I say you are wasting your time and ours doing what you are doing now.

Check out tutorials 1 to 4 on the link I posted above.

TDK

instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 18th Apr 2010 17:04 Edited at: 18th Apr 2010 18:00
.
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 18th Apr 2010 17:13 Edited at: 18th Apr 2010 18:05
Quote: "No disrespect, but why don't you do it properly and learn to program yourself?
"


Not so simple. I had tried before and the code that I had done doubled the number of lines to each bullet added.

"Note: The example programs have been written to demonstrate the process as clearly as possible - not to demonstrate good programming practices. Once you understand how these programs work, [b]you can optimize and improve on them."

Yourself, in your tutorial, allow me to do this with the sentence highlighted: Improve It. And that's what I tried to do as you can see.


Quote: "BulletPosY(N)=BulletPosY(N)-0.2

What do you think this is actually doing? And how is it different from:

BulletPosY(N)=BulletPosY(N)-1
"


then try to vary the speed of the shot with the code of your tutorial.

Quote: "If you learnt to program yourself, you wouldn't need to 'adapt' code written by other people."


You allowed me in his tutorial, adapt it and now regret?

Quote: "I also assume that shortcutting the learning process, you won't even understand the answers we give you to your problems."


You should not have read the topic from the beginning to say that.
instinto criador
17
Years of Service
User Offline
Joined: 19th Dec 2006
Location:
Posted: 18th Apr 2010 17:21 Edited at: 18th Apr 2010 18:00
,
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Apr 2010 21:01
First of all an apology from me. I assumed a little too much.

I'd just spent quite a while answering posts where they had done what I wrongly accused you of doing and was getting too tired. I must be more careful in future...

In my defence, I hadn't picked up on the fact that the line:

BulletPosY(N)=BulletPosY(N)-0.2

..wasn't in the code you started with and it was one of the changes you made trying to optimize it. You also didn't mention that you were trying to modify code from a tutorial. Had you said that, my response would have been a little different.

I knew it wasn't something I would have done in one of my tutorials so I'm afraid I added 2 and 2 together and got 5!

Quote: "Yourself, in your tutorial, allow me to do this with the sentence highlighted: Improve It. And that's what I tried to do as you can see."


In fairness, that assumes that you understand certain things. For example, in that tutorial it also says:

Quote: "This task is exactly what arrays were designed for so if you don't fully understand arrays, go and read the tutorial which covers them now, then come back when you know how they work. In this next section I have to assume that arrays are not a mystery to you as I make no attempt at explaining them."


That's why I asked you if you knew the difference between deducting .02 and 1 from an integer array - just to find out.

In fact, deducting .02 from an integer variable (array or otherwise) is exactly the same as deducting 1. Not knowing this would make it appear that deducting a smaller amount like .02 would move a smaller distance than deducting 1 - when actually it wouldn't.

You need to use float arrays for it to work like that.

Quote: "You should not have read the topic from the beginning to say that"


I did read it all. You just didn't supply all the information required to answer correctly first time around. But I appreciate that English isn't your first language, so you did a lot better than I would in your language!

TDK

Login to post a reply

Server time is: 2024-11-23 16:40:39
Your offset time is: 2024-11-23 16:40:39