Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
22 May, 2013, 07:29:07 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Bullet code bug? -  (Read 183 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
turiqwalrus
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Yesterday at 18:53:43
Date Registered: 25 November, 2010, 00:38:42
Location: In a shadowed grotto far from the eyes of the world.
Posts: 707


Topic starter
Total Post Ratings: +42

View Profile
« on: 21 May, 2012, 19:31:14 »
0

So, hellninjas and I have been trying to figure out some decent code for programming bullets, and we've pretty much got it down now- except for one bug.
when firing a new bullet, a picture of the bullet sprite bullet flashes briefly at the top of the screen.
Could someone find what's wrong?
Also, optimize if neccesary Tongue
Spoiler for code:

0->C+5 -> D
15 -> X -> Y
[18247EBDFFBDFFA5] -> Pic1
[183C3C3C3C240000] -> Pic2
Repeat getkey(15)
X+getKey(3)-getKey(2) --> X
Y+getKey(1)-getKey(4) --> Y
Pt-On(X,Y,Pic1
if getkey(54)
DS<(D,5)
X->{C+1*2+L1}
Y->{C+1*2+1+L1}     
C++
end
end
if C
for(L,0,C)
{L*2+1+L1}-1->{L*2+1+L1}
if {L*2+1+L1}>64
if C>0
Copy(C*2+L1,L*2+L1,2
end
C--
else
Pt-On({L*2+L1},{L*2+1+L1},Pic2
end
end
end
DispgraphClrdraw
end
Logged
Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 05:42:54
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #1 on: 21 May, 2012, 23:05:18 »
0

Your issue arises from this block of code:


1
2
3
4
5
6
If C
For(L,0,C)
.Snip
End
End

I see two issues with this. First, because of how you add bullets, the first bullet is located at L1+2, whereas this loop structure treats L1 as the location of the first bullet. Secondly, this loop will run 0 times if C equals 0, but it will run C+1 times if C doesn't equal 0. For instance, if C equals 1, the loop will iterate for L equals 0 and 1, for two iterations total. This extra iteration in combination with reading data at L1 that's not a bullet is what's causing the issues you're seeing.

Thankfully, the fix for this is really easy. It even allows you to completely remove the If C block surrounding the for loop! Just change the lower bound of the for loop to 1. Smiley


1
2
3
4
For(L,1,C)
.Snip
End

Alternatively, the most optimized way to fix this is with your own loop structure. Tongue


1
2
3
4
5
6
7
C
While
→L
.Snip
L-1
End



And just for fun, here's my optimized version of the entire program. It's also attached. Grin

Spoiler for Hidden:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
.BULLET
0→C→D
15→X→Y
[18247EBDFFBDFFA5]→Pic1
[183C3C3C3C240000]→Pic2
While 1
 Pt-On(getKey(3)-getKey(2)+X→X,getKey(1)-getKey(4)+Y→Y,Pic1)
 !If D
  If getKey(54)
   X→{Y→{C++*2-2+L1}+1}
   4
  End
  +1
 End
 -1→D
 C
 While
  -1→L
  {*2+L1→P}--
  Pt-On({}ʳʳ,/256,Pic2)
  !If -L6
   Copy(C--*2+L,P,2)
  End
  L
 End
 DispGraphClrDraw
EndIf getKey(15)

If the code box is tiny, that's because Chrome fails. Click "Select All" and then press Ctrl+C to copy it, then just paste it into something like notepad to view it.

* BULLETS.8xp (0.32 KB - downloaded 7 times.)
« Last Edit: 23 May, 2012, 18:13:18 by Runer112 » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.363 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.