ID:787674
 
(See the best response by Nadrew.)
Last one for a while, I promise

Problem description:
I'm using FA's interface library so I can use JS in my browser and whatnot. Using rudimentary JS know-how I have made this.

mob

Login()
src.NewScreen = 1
OP = new(src,"Main","OP")
OP.HTML(

{"
<html>
<head>
[JS2DM(src)]
<script>

function addHTML(text)
{
var div = document.getElementById("OP");
div.innerHTML += text;
}

</script>
</head>
<body bgcolor = "black" text = "white">
<div id="OP"></div>
</body>
</html>
"}

)
OP.JavaScript("addHTML","Welcome to Retro RPG. To use commands, type them in the commands bar (located at the bottom of your screen). \
What would you like to do today? Create a new character (Command: Creation) or Load an existing character? (Command: Memory)"
)


Using a verb to call JavaScript seems to work fine, but I when I put OP.JavaScript("addHTML","blah") right after the "browser setup", it doesn't work. I know the line is being reached. So does anyone know why this isn't working?

Note: The browser has been defined as OP.
Try doing it after calling ..() inside of Login().
No change.
Have you tried putting the stuff inside of a proc? What happens if you call said proc from a verb instead of Login()? I've never used F_A's library so I'm not entirely sure what could be the issue.

I've always used straight browsers and call() to execute javascript.
Yes, I've tried both. Using a verb allows it to work, but I was kinda hoping to make it automatic. Here is my test code.

    proc
TestOP()
OP.JavaScript("addHTML","Welcome to Retro RPG. To use commands, type them in the commands \
bar (located at the bottom of your screen). What would you like to do today? Create a new \
character (Command: Creation) or Load an existing character? (Command: Memory)"
)

verb
TestOP2()
OP.JavaScript("addHTML","Welcome to Retro RPG. To use commands, type them in the commands \
bar (located at the bottom of your screen). What would you like to do today? Create a new \
character (Command: Creation) or Load an existing character? (Command: Memory)"
)


src.TestOP() replaces OP.JavaScript() in the first code snippet. I have also tried src.TestOP2(). Same result, it does not output the message.

My debugging statement was an output message that replaced OP.JavaScript(). The message was indeed sent

src << output("Hi","Main.OP")// Main.OP is the browser control

Best response
I'm thinking something in the library is initialized later than Login() and the library requires this to function properly. Try spawn()ing off the call to TestOP() for a few seconds after Login() completes.
That seems to have done the trick. I'll ask FA what the deal is when I seem him online.
My guess is that you were calling the javascript function before the html was loaded. I'm pretty sure there is no initialization taking place in Login inside the library.
So there's a delay in the HTML loading process? Do you know how long?
In response to Lugia319 (#8)
Lugia319 wrote:
So there's a delay in the HTML loading process? Do you know how long?

I don't think there's any way to know. The html is processed and loaded by the client, so there's no way for the server to know when its ready.
Alright. Guess I'll keep that in mind. Good thing it's only done once (for me) I suppose. Could you pop in the Saloon to help me address another issue I'm running into?
In response to Lugia319 (#10)
Lugia319 wrote:
Alright. Guess I'll keep that in mind. Good thing it's only done once (for me) I suppose. Could you pop in the Saloon to help me address another issue I'm running into?

I can't right now, I don't have access to BYOND. You can post about the other issue here or page me.