Functions and For Each Loops...

Get help using Construct 2

Post » Wed Jul 03, 2013 9:11 am

@DaveSilver

to ask someone specifically use the @ symbol in front of their name.

I am just starting to use functions for the first time and despite everything looking logical to me sometimes they just dont work. Like you i have produced workarounds but its a lot of trial and error.
B
45
S
15
G
9
Posts: 1,096
Reputation: 11,038

Post » Wed Jul 03, 2013 2:36 pm

At this point it will probably help if I just post the capx file so people can look at my code and see if they can determine the issue.

https://docs.google.com/file/d/0B_goJNiY1s1STjBoa0RrS2hMN28/edit?usp=sharing%20

The function where I am having the issue is the "CreateStartingBlocks" function. In this function I am creating a grid of Blocks and after I create each Block I assign it a BlockID. I then attempt to call the "RemoveSpawnedMatches" function with the number I assigned as the BlockID as the parameter for the function.

This function is supposed to take in a BlockID, check if there is currently a Block with that BlockID, and if there is it is supposed to ensure that the Block is not neighboring any Block which is the same color as it is.

I know that RemoveSpawnedMatches works because earlier I tried making a separate Event which goes through each Block one by one and sends them into the RemoveSpawnedMatches function and it worked perfectly. Right now I am trying to determine why it won't work in this specific scenario. Any help would be greatly appreciated.Here is the download linkDaveSilver2013-07-03 14:37:11
B
5
Posts: 19
Reputation: 713

Post » Wed Jul 03, 2013 2:50 pm

I cant actually run your program due to some third party addon.

But have you tried instead of making a function called "RemoveSpawnedMatches" just to make it as a On create block and then do the tests there?

Also a workaround, if it suits you program, is to add an Boolean to the blocks, and if its true, that block need to be tested.

So you can just add an event:
"
Block.need_tested = true
For each block

Function call "RemoveSpawnedMatches"
"
And then just turn off/on the Boolean if you need to test a block or not.

nimos1002013-07-03 14:51:29
B
40
S
10
G
2
Posts: 1,151
Reputation: 6,501

Post » Thu Jul 04, 2013 12:00 am

Okay so it seems I have been wrong about what exactly the problem was for a while. Originally I thought that the problem related to the RemoveSpawnedMatches function not firing within the function that creates the Blocks, when in-fact it is firing. The issue is that for some reason the function is never detecting the matches when it fires. Now this is very strange since I know the function works and detects matches perfectly, and have tested it in other scenarios within this same game.

I think the problem has something to do with the fact that the Blocks are being made while it's trying to check for matching neighbors to remove simultaneously and somehow that is preventing it from working. I'm not sure why this would be an issue since it is making the same way you would populate a 2d array and thus even if not every block is made yet it should be able to detct matches perfectly with any existing blocks, but it is an issue nonetheless.

@nimos100, I attempted to implement both of the solutions you've suggested but they both seemed to fail for the same reason that mine does. I even went as far as putting all of the stuff in the RemoveSpawnedMatches function directly into the function which makes the Blocks(on a side note I'm not sure why I didn't do this to begin with) and I still ran into the issue I mentioned above where it gets into the initial part of the function where it knows it should perform the check, but never finds any matching neighbors it needs to modify.

You can download the version which has it setup the way I just mentioned at the link below. You'll notice it also has some disabled code which can act as a workaround to the issue. For now I am just using the workaround until I can find a better solution, but if anyone can figure out why it's not working without the workaround I'd be incredibly grateful.

https://docs.google.com/file/d/0B_goJNiY1s1SM1FEdEhZdnFhVjg/edit?usp=sharing

Also, @nimos100 did you mean that I am using a plugin which prevents you from running it, or that you are using a plugin which prevents you from running it? I only ask because as far as I know I have no plugins in my C2 and it would be a potential issue if I did.

Thanks again for any help that anyone can provide.
B
5
Posts: 19
Reputation: 713

Post » Thu Jul 04, 2013 12:11 am

"I attempted to implement both of the solutions you've suggested but they both seemed to fail for the same reason that mine does."

The last solution should work, you might have to change some code etc, as I use a solution like that in my own program. But you might have to move it above the other event, so it doesn't trigger before next tick.
However its to difficult to figure out, whether it suits your solution or not. As mine is designed to work with such, so its probably better that you use your own if it works for you. :)

"did you mean that I am using a plugin which prevents you from running it, or that you are using a plugin which prevents you from running it? I only ask because as far as I know I have no plugins in my C2 and it would be a potential issue if I did."

I got the information from your program, that I couldn't start it. I don't use, and have never used any plugins. Even though I think a lot of them could be useful, I don't want the troubles with an update to C2 suddenly not working with a plugin I used and then my program doesn't work etc etc. :D

(But ill try running it again and post what it says, just to be sure :))

EDIT: Hmm weird I started it now without any problems. So it must have been a glitch of some sort.nimos1002013-07-04 00:14:02
B
40
S
10
G
2
Posts: 1,151
Reputation: 6,501

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests