How do I debug dictionary keys all return 0

Get help using Construct 2

Post » Sat Oct 04, 2014 8:27 pm

I am reading over this thread now... I want to start off though by mentioning the functions that come with C2 Data Editor are for searching DataSets which are C2 Arrays that are setup in a specific way. Dictionaries only have a key/value so they do not need all those CRUD functions.
B
21
S
5
Posts: 196
Reputation: 1,984

Post » Sat Oct 04, 2014 8:29 pm

No, because it works when I isolate it. Gimmie a few minutes, lemme make a copy and strip all the resources
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:36 pm

skelooth wrote: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??


Well lets start off by finding the code for the Dictionary 'Get' expression. It would, of course, be in the plugin for the dictionary. That means it will be in Dictionary_plugin.js (in preview mode). Looking through the file, you can see all kinds of function definitions for the conditions, actions, and expressions. Eventually you will see this:
Code: Select all

Exps.prototype.Get = function (ret, key_)
   {
      if (this.dictionary.hasOwnProperty(key_))
         ret.set_any(this.dictionary[key_]);
      else
         ret.set_int(0);
   };


So if it can't find the key, it returns 0. Why can't it find the key? A quick google search tells me that hasOwnProperty is a built in javascript function that tells you if a value exists on an object. So how do we know if the value exists? Set a breakpoint on the line that calls hasOwnProperty, and trigger your broken event (Firefox seems to be really bad at setting breakpoints, use Chrome for this). The browser will stop the game when it calls the Dictionary Get expression (from any part of your event sheet). At this point, hover your mouse over the 'this.dictionary' text, and it will show you all the values that are in it, and if you hover over _key, it will tell you what value it is trying to get. You may be looking at any one of the calls to this function that your event sheet triggers, so it may or may not be the one you are looking for. If not, tell the browser to continue, and it will show you the next call. What you do from here depends on what you find out.
B
54
S
19
G
13
Posts: 97
Reputation: 10,146

Post » Sat Oct 04, 2014 8:40 pm

I wasn't able to upload it via the forum, I thought deleting resources would lessen the file size but apparently not :) the capx is at

http://surolace.com/play/game.capx and the problems all surround the events in commlink when trying to access the dictionary or array in the openDialog function.

I've been looking at it so long I was hoping it was something stupid in my code I was over looking.

@johncw87 thanks! I'll try some breakpoints now
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:40 pm

Ok look at this CAPX and pay special attention to how

1) I created a Dictionary
2) Saved the UID for the Dictionary
3) Re-"picked " that same Dictionary by UID later on and got its data

There are other ways of doing things but this is how I always do it... basically in my mind the UID is a pointer to a specific instance like in C++ coding.

https://dl.dropboxusercontent.com/u/277541264/ShowDictionaryWorking.capx

ShowDictionaryWorking.PNG
You do not have the required permissions to view the files attached to this post.
B
21
S
5
Posts: 196
Reputation: 1,984

Post » Sat Oct 04, 2014 8:47 pm

Also please remember to rate and review C2 Data Editor in the store!
B
21
S
5
Posts: 196
Reputation: 1,984

Post » Sat Oct 04, 2014 8:51 pm

ggibson1 wrote:Ok look at this CAPX and pay special attention to how

1) I created a Dictionary
2) Saved the UID for the Dictionary
3) Re-"picked " that same Dictionary by UID later on and got its data

There are other ways of doing things but this is how I always do it... basically in my mind the UID is a pointer to a specific instance like in C++ coding.

https://dl.dropboxusercontent.com/u/277541264/ShowDictionaryWorking.capx

ShowDictionaryWorking.PNG


Here comes my weird question about scope, and hopefully this is what I'm being tripped up on (I have implemented this yet, but purely in terms of the environment):

If I only have one Dictionary object, wouldn't

Dictionary->PickbyUID

Dictionary(0)

or Dictionary

All yeild the same results when picking?



I made your example look more like mine and you're right, it broke. Am I understanding how it picks incorrectly? Sorry to bug you :) The question is open ended to anyone
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:53 pm

The picking system seems somewhat complicated and I think that it might be context sensitive. I got tired of trying to use picking in different ways and now I use UIDs for everything. So I really cannot answer your question about how picking works in every situation. I just know if you standardize on UIDs it always works (Except when you forget to pick an object by UID before using it)
B
21
S
5
Posts: 196
Reputation: 1,984

Post » Sat Oct 04, 2014 8:56 pm

The picking system may be a little complicated, but if you only have one instance of an object type, you don't have to worry about it at all.

EDIT:

Actually, I was just reminded of a certain behavior that might be tripping you up. If you create an object, and then in a different event on the same tick, try to use an action on it, it won't work unless you had picked it by UID. All other forms of picking don't work properly for objects that were created in the same tick.
B
54
S
19
G
13
Posts: 97
Reputation: 10,146

Post » Sat Oct 04, 2014 9:11 pm

Johncw87 wrote:Actually, I was just reminded of a certain behavior that might be tripping you up. If you create an object, and then in a different event on the same tick, try to use an action on it, it won't work unless you had picked it by UID. All other forms of picking don't work properly for objects that were created in the same tick.


That's why I had wait 0.0 before. Waiting for the next frame pushes the object into scope.

Thank you so much @ggibson1 !! That fixes it. For some reason picking does not work as I thought it should under the context, and although I'm not sure "why" picking is being weird, selecting by UID does fix it and makes everything work as normal! Thank you!
Developing Surolace, the survival role playing space game.

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

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: dop2000, Yahoo [Bot] and 26 guests