How do I debug dictionary keys all return 0

Get help using Construct 2

Post » Sat Oct 04, 2014 5:01 pm

I've been going in circles trying to figure out why dictionary objects do not work in my project (but work fine in blank projects).

ALL dictionary values look okay in chrome browser debug and in construct2 native debugger

dictionary.asjson() works fine as well and shows all values,

but dictionary.haskey and dictionary.get do not work at all and only return 0 and I have no idea why.


Here is all of the relevant code from my project:

http://imgur.com/a/ntsNL



It's messy because I've spend the last 8 hours changing random things, commenting things out, and pumping out values to try and figure out why "haskey" and "get" don't work on my dictionaries, but it works fine in a new project. Obviously I need it to work in this project and I have no clue what's going wrong.

If you look I also had to make buffer variables to hold on to the parameters because the parameters DISAPPEAR!!!!! if I try to use them in a sub event. I am completely not understanding scope or how this works or something.
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Sat Oct 04, 2014 7:08 pm

@skelooth I once used dictionary, honestly I don't really like it because of things that happen to you, once happened to me. I would like to suggest you to use array instead, no particular reasoning to this it just my preference. I rather use dictionary to store simple things only.

Similar functionality you can exploit:
Dictionary: haskey; Array: [condition:contain value]
Dictionary: get; Array: array.at(array,indexof("xxxx"),#)
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Sat Oct 04, 2014 7:17 pm

I even bought the c2 data editor out of desperation....

here is all the relevant code using nothing but the functions given by the c2 data editor! but again it works fine in a blank object. -_-

Image

In this example, plundermoon0 is the key in a dictionary that c2dataeditor functions load... asjson still works as normal. I'm kinda losing my mind :)
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Sat Oct 04, 2014 7:36 pm

Is there a chance that your miserable situation caused by the c2dataeditor? Probably tag the seller would be a good idea to ask his assistance. I haven't use browser.ExecJS before because I don't know how, so I can't tell whether those parameters are properly forwarded or not.

It's rare to see advanced question like this though, hopefully better users can give some hint. :D
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Sat Oct 04, 2014 7:54 pm

This is going to kill. I just switched everything out to arrays.

The capx is already kinda big with a lot of files, but I'm stuck.

The problem is on the event sheet "commlink"

On buttoncommlink press, it calls create data from the c2 data editor then calls my function "open dialog" right below.

Open dialog just needs to be able to read a value out.... that's, all. -_- I do not have any idea of why it's not working

Oh damn, it's too big to upload here
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Sat Oct 04, 2014 7:56 pm

No, I don't think it's the c2 data editor's fault at all. There's something I'm not understanding about scope or something, and why it's being clobbered. Literally all of the code involving what I'm trying to do is in those screen shots, I know b/c I went around and Ctrl F'd everything a few times :P
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Sat Oct 04, 2014 7:59 pm

skelooth wrote:If you look I also had to make buffer variables to hold on to the parameters because the parameters DISAPPEAR!!!!! if I try to use them in a sub event. I am completely not understanding scope or how this works or something.


Well this is an easy one. Functions are triggered events, and function parameters are only good during that triggered event. But when you use a wait action, everything that happens after it is no longer inside that triggered event. It has been scheduled to run at a later time, and then does so. It does not matter that the wait time is 0.0 seconds, it will still kick the following actions and sub-events out of the triggered event and cause function parameters to fail.

As for your dictionary problem, my recommendation is to get very friendly with your browser's javascript debugger. Run your project in preview mode, and try to find the javascript functions that correspond to the condition and expression that are failing. Set a breakpoint in them right before you trigger something that you know isn't working properly. Then try to use the available information in the debugger to see why it isn't working.
B
54
S
19
G
13
Posts: 97
Reputation: 10,146

Post » Sat Oct 04, 2014 8:01 pm

Hey @ggibson1 Have you ever heard of this behavior, or see anything glaringly wrong with the code above? I can't seem to get arrays or dictionaries to admit they have values, even though their asjson expression output correctly. I don't think it's the c2 data editor's fault, but I figured you'd probably know better than most.
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Sat Oct 04, 2014 8:05 pm

Johncw87 wrote:
skelooth wrote:Well this is an easy one. Functions are triggered events, and function parameters are only good during that triggered event. But when you use a wait action,


Wait function was temporary and was removed, it was there hoping maybe the object was not in scope and would be available in the next frame. That was not the case.

my recommendation is to get very friendly with your browser's javascript debugger. .


If you see the above code, the majority of it is eval statements and console logs. Me and the chrome debugger spend many hours together every day. All javascript objects are populated correctly, but return values all return '0' for all arrays/dictionaries on get/haskey. Unless you can tell me how to specifically watch the process where the C2 engine is getting this 0??
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Sat Oct 04, 2014 8:23 pm

Can you isolate the issue in a capx and share it with us ?
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Next

Return to How do I....?

Who is online

Users browsing this forum: Cubeeo and 17 guests