Real issue. Here's a gadget showing the problem:
(Choose update state from one view, then the other; you'll see two
update calls from the wave api for each call to submit delta).
Only tried this with two clients at once; I wonder if it scales to the
number of people currently having the gadget open...
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="State Example" height="350">
<Require feature="wave" />
</ModulePrefs>
<Content type="html"><![CDATA[
<style>
div {
margin: 10px;
border: 1px solid #000;
font-family: Arial;
font-size: 10px;
height: 60px;
overflow: auto;
}
</style>
<div id="state"></div>
<div id="log"></div>
<div>
<b>Commands:</b><br/>
<a href="#" onclick="state.update(); return(false);"> Post
Update </a> |
<a href="#" onclick="state.refresh(); return(false);">
Update from state object </a> |
<a href="#" onclick="state.clear(); return(false);"> Clear
log </a>
</div>
<!-- Gadget bootstrap. -->
<script type="text/javascript">
var state = {
// State objects we're following
'states' : [
'state1',
'state2',
'state3',
'state4',
'state5'
],
// Logging target.
'log' : document.getElementById('log'),
// Log index.
'index' : 0,
// State target
'state' : document.getElementById('state'),
// The id of this node.
'id' : Math.floor(Math.random() * 100),
// Fetches state from log.
'refresh' : function() {
state.trace("Refresh requested.");
state.updated();
},
// Traces a log message.
'trace' : function(msg) {
var id = state.id + " -- " + state.index + " -- "
+ Date() + " -- ";
++(state.index);
state.log.innerHTML += id + ": " + msg + "<br/>";
},
// Fetches the state from the wave.
'updated' : function() {
state.state.innerHTML = "STATE:<Br/>";
for (var item in state.states) {
state.state.innerHTML += state.states[item] +
": ";
state.state.innerHTML += wave.getState().get
(state.states[item]) + "<br/>";
}
state.trace("Fetched wave state and displayed.");
},
// Posts an update to the wave.
'update' : function() {
var viewerId = wave.getViewer().getId();
var updates = [];
// Update
var update = {};
for (var item in state.states) {
state.trace("Recorded an update
for: " + state.states[item]);
update[state.states[item]] =
state.id + ": Set this value.";
}
state.trace("Posted state update.");
wave.getState().submitDelta(update);
},
// Gets an update from the wave itself
'waveUpdate' : function() {
state.trace("Wave posted an update event.");
state.updated();
},
// Clears the log.
'clear' : function() {
state.log.innerHTML = "";
state.index = 0;
},
// Starts...
'init' : function() {
if (wave && wave.isInWaveContainer()) {
wave.setStateCallback(state.waveUpdate);
state.trace("Loaded and ready.");
}
}
};
gadgets.util.registerOnLoadHandler(state.init);
</script>
]]></Content>
</Module>
~
Doug.
On Jan 15, 5:23 pm, HaiColon <[email protected]> wrote:
> I'm actually submitting four things with each call to submitDelta(),
> but I only get two callbacks instead of four so this can't be directly
> related. But it's interesting to see that combining two values into
> one worked for you, hopefully this additional info will help the Wave
> team to find the bug.
>
> Here's the link to the bug report I filed if anyone wants to track
> it:http://code.google.com/p/google-wave-resources/issues/detail?id=623
>
> The bug report also links to this thread for additional information.
>
> On Jan 16, 1:25 am, jhouk <[email protected]> wrote:
>
> > Hi Chris,
>
> > I don't suppose the delta that you're submitting is two values? I
> > found to my surprise when working with submitDelta for the first time
> > that my gadget got a callback from Wave for each value submitted in
> > the delta, instead of the entire delta object getting passed back to
> > the gadget in a single callback.
>
> > Since the data I was submitting in my case was tightly coupled, I
> > combined the data into a single JSON string value and submitted it in
> > a single submitValue() call instead and it worked great.
>
> > Hope this helps,
> > --Justin
>
> > On Jan 14, 10:02 am, HaiColon <[email protected]> wrote:
>
> > > I'm currently writing a multiplayer Match 3 style game for Google Wave
> > > (Match 3 = If three or more blocks/gems/whatever of the same color are
> > > aligned horizontally or vertically, those blocks are destroyed, giving
> > > you points. The blocks above the destroyed blocks fall down and the
> > > now empty space at the top is filled with new random blocks, giving
> > > the illusion of an endless supply of new blocks falling down. A game
> > > move can swap one block with another one that has to be 1 block to the
> > > left, the right, up, or down of it and the move has to cause the
> > > destroying of blocks or the move is invalid).
>
> > > With every move made I do a submitDelta, submitting the game move.
> > > What's happening now is that first, Wave sends the last state that was
> > > sent through a prior call to submitDelta() (the game move before this
> > > one) and then it sents the new state that was submitted with
> > > submitDelta() just now, thus sending every submitDelta() twice. I
> > > verified with wave.log() that my code only sends one update so I'm
> > > 99.9% sure that it's not a bug in my code.
>
> > > Is this the intended behavior, or a bug? And if it's intended, why is
> > > that so? :) I can't really think of any reason why this would be
> > > intended behavior but I may well be wrong.
>
> > > To circumvent this behavior, I added a timestamp to every submitDelta
> > > () call and my code checks the timestamp and doesn't apply the changes
> > > it receives if it already received a state change with this timestamp.
> > > This seems to be working fine. Here's a video I made just now of the
> > > game in action with this workaround
> > > applied:http://www.youtube.com/watch?v=bdrBIW50N4k
>
> > > Also, could someone shed a bit of light onto how Gadget state works
> > > exactly? From looking at the debug log in Wave, it seems that with
> > > every submitDelta, everything you ever stored in the gadget state is
> > > sent over the network, instead of just the parts you just submitted
> > > with submitDelta. Is this true? For my game this is a bit overkill. I
> > > have to store a few hundred (maybe thousand) pre-generated random
> > > colors for new blocks (those that replace destroyed blocks) so that
> > > every Wave user of the gadget sees the same new blocks in his Wave
> > > client when blocks are destroyed after a game move. I only need this
> > > list of colors transferred once every time you open the wave that
> > > contains the gadget, so sending it only once would suffice. It does
> > > look like Wave sends this list of random colors with every game move
> > > though, even if I don't access it with wave.gadgetState().get
> > > ("randomColors"). I hope I'm wrong about this ^^
>
> > > Thanks in advance for any information about this.
>
> > > Cheers,
> > > Chris
--
You received this message because you are subscribed to the Google Groups
"Google Wave API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-wave-api?hl=en.