Computer Science Canada Shooting multiple times |
Author: | ficca951 [ Thu Jan 19, 2012 3:46 pm ] | ||
Post subject: | Shooting multiple times | ||
What is it you are trying to achieve? I am trying to create a shooting game. What is the problem you are having? I am having an issue with having multiple bullets on screen at once. Describe what you have tried to solve this problem I have tried searching around on compsci but nothing appears to be exactly what I am looking for. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) I figured that using a process for shooting would allow me to shoot multiple times without stopping any other bullets, unfortunately I keep receiving the error: "Process "shoot": Variable has no value." each time I press the button to shoot. Any advice would be appreciated. Right now the only thing you can do is press space to shoot, but I intend to have mobility later on. I just really want to get over this hiccup before I continue.
Please specify what version of Turing you are using 4.1.1 |
Author: | Alex C. [ Thu Jan 19, 2012 4:08 pm ] |
Post subject: | RE:Shooting multiple times |
well its not "shoot" that has no value, its the variables that are IN that process such as "bulletx & bullety". therefore you have to give that varaible array a value somehow |
Author: | ficca951 [ Thu Jan 19, 2012 4:12 pm ] | ||
Post subject: | Re: Shooting multiple times | ||
I assumed I was doing so with
|
Author: | Alex C. [ Thu Jan 19, 2012 4:16 pm ] |
Post subject: | RE:Shooting multiple times |
oh oops, im sorry. maybe if you don't make it a process... the bullet doesn't move though :/ |
Author: | copthesaint [ Thu Jan 19, 2012 4:17 pm ] | ||
Post subject: | Re: Shooting multiple times | ||
First issue is you are using a process, Which is BAD! unless its for music or internet dont use it. Second you need to start your flexible array 0..-1 of int because the way you are doing declairing your array you have two null values, bullet_x (0) and (1) third thing is that in your process you are always ONLY manipulating the upper () value of bullet_x which means if there are 5 bullets you are only drawing the 5th. You need to manipulate them all by putting it in a for loop from the first value (0) to the last value (upper (bullet_x)) forth thing is you should really put the values of the bullet in a type. Meaning instead of two variables make it
Thats all I have to complain about ![]() |
Author: | copthesaint [ Thu Jan 19, 2012 4:18 pm ] | ||
Post subject: | Re: Shooting multiple times | ||
Here is an example for using a flexible array.
|
Author: | Dreadnought [ Thu Jan 19, 2012 4:29 pm ] |
Post subject: | Re: Shooting multiple times |
First off, you don't need processes and, in my opinion, they are usually evil. You're main code is itself a process. When you fork a process you tell Turing to run both processes simultaneously. That sounds nice, and you figure that with most computers being dual or quad core that this would be achievable. But Turing does not run concurrent processes side by side. Instead, it switches between the processes in a quick and mostly random fashion. Now, keeping this idea in mind consider what's going when you run you program. Your "shoot" process updates a variable in a flexible array. In your case it checks what the highest index of the array is and updates that value. That's already a behavior that I assume is undesired, since you could have 10 processes and they would all only affect the upper index of the array. Also, recall that the execution in random. Say you hit space, you create a new index in the array, but now Turing switches to one of your "shoot" processes and tries to update the highest index of the array. But we just created that index and haven't had time to assign it an index. This is the cause of your errors. There are ways of making this work with processes but I strongly suggest you don't make use of processes for this. Instead, I recommend that you view things differently. You have two arrays representing the coordinates of your bullets. You want to update these coordinates. You could have a process for each but is each process doing that is unique to itself? The only thing that is unique might be the index of the array that the process is updating. But if you could somehow use a loop to go through all the indices and update each one then you wouldn't need multiple processes. Also, once you get your bullets working I suggest you try to make sure that the arrays don't become full of old bullet coordinates that you don't need. Hope this helps. EDIT: looks like copthesaint beat me to this. |
Author: | ficca951 [ Thu Jan 19, 2012 4:46 pm ] | ||
Post subject: | Re: Shooting multiple times | ||
Thank you for the input ![]() I have listened to what you guys have said and it is definitely understood that PROCESSES ARE BAD. Also I just realized my error about only using the the latest array ![]() Here's what I have:
|
Author: | ficca951 [ Thu Jan 19, 2012 5:03 pm ] | ||
Post subject: | Re: Shooting multiple times | ||
Okay, this seems logical to me but it has a weird glitchiness to it. :/
|
Author: | Alex C. [ Thu Jan 19, 2012 5:25 pm ] |
Post subject: | RE:Shooting multiple times |
actually you just need to use setscreen ("offscreenonly") and View.Update... there is a tutorial for that |
Author: | copthesaint [ Thu Jan 19, 2012 5:31 pm ] |
Post subject: | RE:Shooting multiple times |
IF you cannot figure out why its drawing the way it is, then I suggest not even using flexible arrays and learn the language more since you likly just copied n pasted your code. if someone else wrote it for you, ask them for help. |
Author: | Raknarg [ Thu Jan 19, 2012 6:43 pm ] |
Post subject: | RE:Shooting multiple times |
I found that using a flexible array for bullets was mroe trouble than it was worth. I'm assuming the idea behind that was "Well, Idk how many bullets are going to be on the screen at any time, so I'm just going to change the array to the bullets!" That is unecessary. Instead, I would recommend you use a regular array with an upper bound that you know won't ever be attained. (If you think there will be about 15 bullets, make the array size 20). The problem you'll run into with this is that eventually the amount of bullets will become so large that the program starts to lag. |
Author: | Alex C. [ Thu Jan 19, 2012 8:33 pm ] | ||
Post subject: | RE:Shooting multiple times | ||
would you like to see how i did shooting? just replace all the Pics with like dots or something
|
Author: | evildaddy911 [ Thu Jan 19, 2012 11:53 pm ] | ||||
Post subject: | Re: Shooting multiple times | ||||
If you dont know how many bullets you will need, then do that first. One way is, if the wondow borders are the boundaries for your game, then the upper should be round( Math.Distance(0,0,maxx,maxy) ). then, in order to reuse bullets, you need a boolean "live" varable.
Then when you fire, you need to find an unused bullet to fire,
|
Author: | ficca951 [ Fri Jan 20, 2012 10:46 pm ] |
Post subject: | Re: Shooting multiple times |
Thanks for the help guys, I appreciate it. I have managed to find a solution and I'd like your opinions. Obviously this isn't complete, but its the main function. |