PDA

View Full Version : throwDice and customdata issue?



Moon Wizard
November 1st, 2009, 07:06
I was just working on a feature for my ruleset that performs multiple dice rolls on a double-click event. For each roll, I call chatwindow.throwDice with a different customdata value.

However, when the rolls complete and chatwindow.onDiceLanded is called, all of the rolls have the same customdata value. The customdata value returned in all instances of onDiceLanded use the customdata value of the last roll performed in the set.

It looks like the customdata value is getting overwritten whenever chatwindow.throwDice is called, regardless of whether there are other outstanding rolls in progress.

Anybody else encounter this issue, or found a workaround?

Thanks,
JPG

Foen
November 1st, 2009, 09:22
I've not bumped into this, but thanks for documenting it. I imagine FG caches the customdata in a static location until the physics engine has finished its stuff and then retrieves it for onDiceLanded. Multiple calls would then overwrite the data.

If that is the case, then I think it might be hard to change the behaviour: using a queue instead of a single static wouldn't work if the rolls don't complete in the order they were invoked.

Stuart

Fenloh
November 1st, 2009, 10:46
I dont know what you exactly want to do, but i am sure, that the process you are referring to is always using the same Variable to store the information and thus overwriting it. That means, that you have to store data in different Variables, before you fetch the next data. Local Variables may work, but probably you need to store it under a node in the database, depending on what you do and when you do it.

Depending on the situation you can either use the sequence to determine in which variable you write the data and sum them up in the end, or you use a counter if you are using loops. You may even want to consider to put the data in the database.


Fenloh

Moon Wizard
November 1st, 2009, 17:36
One other situation that I uncovered during the process.

In addition to the getCustomData being shared between throwDice rolls: if the variable is a table, then the pointer to the actual table is returned. This means that any changes you make to the table variable will be reflected in all the other rolls as well.

My workaround has been to add all the data I want to pass for all rolls into one giant customdata object. Then, I pass a tag in the description variable for the throwDice call, which I use to index the correct data out of customdata object.

Not the best workaround since I've had to consistently add tags to the description in order to retain information about rolls, which has caused the roll descriptions to become very long and wrap, but it works.

Cheers,
JPG