naval battle

Get help using Construct 2

Post » Wed May 09, 2012 6:45 am

hey working on my shipbattle system :)

i got some problems,

basicly is want to know if my ship should shoot left or right or both
i had something going but it doesnt work for multiple ships

i was thinking of using pickedcount and is clockwise or not, so when there
nr of ships is clockwise, enable right shooting
nr of ships is counterclock enable left shooting
but it doesnt work

by the way, should pickedcount not give a -1 or something if nothing is picked, its not very usefull like this


i prepared a cap for testing, so if somebody wants to help, cause im hitting a wall here

http://dl.dropbox.com/u/61666915/navalbattle2.capx
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Wed May 09, 2012 6:50 pm

is it hard to do maybe? any idea's?
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Sun May 13, 2012 10:51 pm


don't have a solution for you, but I think I'm having the same sort of problem, and i think it's due to me not understanding picking instances very well

anyway, here's what i would like to do:

1) generate a random amount of enemies on the screen in random positions (i've been able to do that much!)

2) i want to be able to recognize what side of the player sprite the enemies are (this is where i'm getting tripped up);
   
   if i manually create a single instance of the enemy sprite and place it on the view area myself, it seems to work

   I was thinking if i go through an 'every instance of enemy sprite' loop and check if it's clockwise or counterclockwise from the player sprite it would work but nope!

anyway, here's the capx -

http://dl.dropbox.com/u/62693846/WhatSideAmIOn.capx

hope somebody can help

thanks
B
11
S
2
Posts: 20
Reputation: 1,042

Post » Mon May 14, 2012 4:03 am

B
79
S
24
G
54
Posts: 4,753
Reputation: 40,769

Post » Mon May 14, 2012 6:57 pm

@ROJOhound very nice, thank you!
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Tue May 15, 2012 1:41 am


@ROJOHound

thanks for quickfix, but I do have to ask... HUH!

i can see it working, but logically i don't get it, why wouldn't my way of looping through each instance of sprite not work,

or in other words why do you need to create a new instance variable just to assign it a UID that's created automatically anyway
B
11
S
2
Posts: 20
Reputation: 1,042

Post » Tue May 15, 2012 6:15 am

@heater19
Yeah... I agree I left out my my logic for the fix, which makes it not very helpful. So here's my trail of thought:

Events 5-7 in your original capx only filtered the "Sprite" object. "Sprite2" is unfiltered and only the first instance of "Sprite2" is used in the expressions. "Text" is also not filtered. So it runs like this: [code]if "Sprite" is CW from the first "Sprite2" then set all the "Text" objects' text to 'Left'.
if "Sprite" is CCW from the first "Sprite2" then set all the "Text" objects' text to 'Right'.[/code]
Relevant section of manual: http://www.scirra.com/manual/75/how-events-work

So there are two problems.
1. Only the first "Sprite2" is being compared against. Changing "Every tick" to "for each Sprite2" in event 5 fixes that.

2. All the "Text" objects are getting set to the same value. What is needed is a way to be able to pick the "Text" that's paired with "Sprite2". Unfortunately he pin behavior doesn't cause the pinned objects to be picked, so some other method needs to be used.

I like using a instance variable to store the UID of another object, so that the paired object can be picked at any time with "pick by UID", but that is not the only solution. You could alternatively use [code]Text|Pick nearest to (Sprite2.X, Sprite2.Y)[/code] or [code]System|pick Text instance Sprite2.IID[/code] and you would avoid the need for an additional variable.
B
79
S
24
G
54
Posts: 4,753
Reputation: 40,769


Return to How do I....?

Who is online

Users browsing this forum: Renfd, supreme676 and 27 guests