On Sun, Mar 23, 2014 at 3:23 PM, Brian Schott <[email protected]> wrote:
> the client has to initiated the request
> with a exactly one jdoajax(), right? So the client is not going to ever be
> able to accept extra jhrajax's that were not expressly requested. Or, if
> that is wrong, then I would like to be told about how it is done, because
> that may be the only solution to my problem.

Correct, with HTTP, the client has to initiate the request and can
only handle one response. It's a full duplex channel with websockets
but I don't think you need that.

> Absolutely, it helps. Do you still think deferred objects is the way to go,
> and there is no hope for accomplishing my goal using J features?
>

I don't see why deferred objects are needed. I'm still trying to
understand why it's not possible to return the list of moves that are
necessary. If J returned the list of moves necessary and that list was
appended to any existing list, that would seem to solve the problem.

I don't understand all the arrays in your code (nor do I need to right
now), but let's take an incredibly simplified example. The paint
routine should be able to operate on a list of [X1,Y1, X2,Y2,
Direction]

Psuedo code:

function drawSteps(steps) {
clearCanvas();
for(var i = 0; i < steps.length;i++) {
var step = steps[i];
paint(step)
}
}

function paint(step) {
//draw line starting from X1,Y1 to  X2, Y2 Indicate the direction of
the turtle's head with direction (looking up, down, right, left, etc)
}


Assuming something as simple as that. If I I told the turtle:

goto 2,5

Then, given the turtle's current position, JHS can figure out how to
get the turtle there in a series of lines.

Let's pretend the turtle is oriented at 0,0. It might need to take
these steps, which is supplied back from JHS

[[0,0,2,0,RIGHT],[2,0,2,5, UP]]

The drawSteps operation loops over those steps and makes a backward L

  |
  |
  |
  |
--|


Now the user sends r 1 to tell the turtle to move right 1 step

The server sends back
[[2,5,3,5,RIGHT]]

Javascript appends it to the existing array, so that array looks like:


[[0,0,2,0,RIGHT],[2,0,2,5, UP], [2,5,3,5,RIGHT]]

It calls drawSteps which clears the canvas and operates on all the steps


I don't know if I have my X/Y stuff right, but hopefully the concept is clear.

So, I don't really understand what the problem is still given my
explanation from before. The server sends back the list of steps
necessary to complete the movement. The steps are appended to all
existing steps to create a list of all steps to be painted.

Happy to help further if I understood the issue within this context.


SIDEBAR: I would recommend having the ajax call also supply the
current position of the turtle. This would allow JHS to be stateless,
which would be a better design if multiple people would ever want to
draw turtles at once. Also, the server doesn't really need to
"remember" the position anyways.

So, in this design, a user enters r 1 and the data to the server is
something like:

2,5 r 1

or

0,0 goto 0,5

I get that there is more complexity with multiple turtles, but wanted
to start simple

You could even prototype this in J without using JHS and come up with
test cases to work out the logic (maybe you already have)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to