How to call function from other javascript


#1

I suggested some idea of javascript library. for pascal users a unit. so tring to make that myself.
But sofar all examples i have tried on internet seems not copatible with hfi. or im doing it wrong.
because building your own units/library’s can be usefull with hifi.

Can you call from 1 javascript a function from other javascript ? and how’s that done in hifi ?


#2

I haven’t looked at it but yes it will be useful and eventually it will probably work in some form because people are likely to want to interact with the likes of Perl or PHP for some functionality I’d imagine.


#3

Only thing i wanted is to call a function from javascript B and parce parameters if needed to a function in javascript B. that way you can make function and reuse it, thats the idea.


#4

To my knowledge you can’t do that, but you can copy the function from the other script and incorporate it into your script.


#5

I agree with that, i have seen javascript to much like normal programming language. But that can not work in a virtual world sofar i know. to much overhead and unwanted memory useage.


#6

If one script includes the other script then you can share variables and functions. For example, editModels.js includes toolBars.js in order to use the latter’s Overlay2D, Tool, and ToolBar objects.

The trick is that items declared with “var” aren’t shared but items declared without “var” are shared as properties of the global object which is common to the two scripts if one includes the other.


#7

This is possible - for example, all the separate animation files for the procedural controller are loaded and functions called by the main script (walk.js).

Also, some scripts load up the proceduralAnimationAPI.js script ( http://highfidelity-public.s3-us-west-1.amazonaws.com/scripts/proceduralAnimationAPI.js ) and use it’s functions
e.g. http://highfidelity-public.s3-us-west-1.amazonaws.com/scripts/bot_procedural.js

Regarding script resource usage, so far I’ve been both surprised and impressed by how much computation I can get JS to do in one frame - HiFi JS is certainly far, far more powerful than LSL!
We do need to keep an eye on this though. I plan to start implementing some very basic resource usage tools this week…

  • davedub

#8

I made a script that i want to show friday. But already discovered that o can push hifi over the framerate edge when i do to many things in short time. So good script for the resource test. Adjusted the script now so the framerate dont drop on my screen.


#9

@Richardus - I’m very much looking into script limits at the moment - can I ask a couple of questions?

  1. When you push HiFi over the framerate edge, what sort of operations are you doing? e.g. filling up big arrays, doing lots of maths, transforming images - would be useful to know.

  2. How do you detect when the framerate edge is hit? Does the viewer start running laggy or are you measuring frametimes?

  3. Could I get a copy of your script with some brief notes on how to push it over the limits?

Cheers!

  • davedub

#10

@Chris got the same script from me @davedub, he wanted to send it to soemone but i forgot the name. You can have the same script, if i know to where i need to send it.

The framerate is dropping for me when you let more entitys appear.
Also on @Ai_Austin domain my framerate is droppen because some more heavy mesh,
you better ask @Ai_Austin about that Only looking at the FPS meter, if that start tod drop things start to move less smooth and thats something i never like :open_mouth:

Lagg in High Fidelity, uhmm, need to figure out first what is lag in High Fidelity :wink:


#11

There is definitely a need to be able to include one file and to be able to call its internal methods and access its variables from another. We need shared memory space for Javascript includes. Including it multiple times is lame.