Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  JavaScript    Load new scene using a network path

Moderators: e_phoenix13
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
<gooky>
Posted
Loading a new scene using javascript requieres(as far as I know), that you change the backslashes to slashes. A normal path looking like this:
c:\pathToMtxFile.mtx
needs to be passed in the LoadMTX as
c:/pathToMtxFile.mtx

My problem is now that I have all the files on a machine on the local network but still I want to be able to see the files. I have had difficulties writing the path.
I tried \\networkmachine/path/mtxFile.mtx

That does not help.
Also:

//networkmachine/path/mtxFile.mtx

is not working. How do you do this?
 
Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of viewpoint d-d
Posted Hide Post
Hi,

This is a somewhat wordy answer, because I'll put it into the FAQ's.

You've come across an old problem with sz strings (strings terminated by zero) that started with 'C' and is inherited by JavaScript. When you want to put a special character into one of these strings, like a line-feed for example, you "escape" it by putting a backslash before it. Whenever the string parsing functions encounter a "\" backslash within a string, they look at the next character to see if it's one of the known special characters. If it sees "Hello\nWorld" then in place of the \n, it inserts line feed character. So if your string (your network path) has backslashes in it, you can see how the string parser is going to be constantly looking at the characters following the backslashes. In some cases it will see a character it doesn't recognize as having special meanings and totally ignore it, in other cases (like \t and \n for example) it will convert it into the special codes required (for tab and linefeed for example).

So because backslash has this special meaning, they had to come up with a way of being able to put a backslash into the string, simple, escape it with a backslash. So for every backslash you want in a string, you need two e.g.:

"\\\\myserver\\subdir1\\subdir2"

Likewise, if you wanted to set a property into an MTX file using vmp.SetProperty, and the string you wanted to have set is "Hello\nWorld", then you'd need to set it to:

vmp.SetProperty(~,~,"Hello\\nWorld",~);

This way, the backslash did actually make it into the XML scene unconverted.

It can get worse too. I recall having to do something like this for one case. If you were doing that setproperty with the property coming in through a function call, you'd would need to double up again e.g.:


function myfunc(x)
{
vmp.SetProperty(~,~,x,~);
}

myfunc("Hello\\\\nWorld");

This may not always be necessary, but it's worth keeping in mind, as it may solve a problem one day.

-Derek
 
Posts: 793 | Location: Viewpoint, New York, New York | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
I am a little confused reading your letter, but still I got the essence.

My concern comes from accessing javascript from c#.net. In that case I found that replacing \ with \\\\ would do the trick when calling the javascript function
 
Posts: 47 | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
Junior Member
Posted Hide Post
quote:
Originally posted by gooky:
I am a little confused reading your letter, but still I got the essence.

My concern comes from accessing javascript from c#.net. In that case I found that replacing \ with \\\\ would do the trick when calling the javascript function



private static string NormalizeScript(string source)
{
return source.ToString().Replace("\"", "\\\"").Replace("\"", "\\\"");
}

Wink
 
Posts: 4 | Registered: March 12, 2007Reply With QuoteEdit or Delete MessageReport This Post
  Powered by Eve Community  
 

Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  JavaScript    Load new scene using a network path