How can i call the coffee script function on body load - coffeescript

I am using the app.coffee coffee script file to create some animations on the framerjs prototyping tool. what i want to achieve is that i have defined a function and i want to call that function on body load. how can i do that in coffeescript?
Code:
changeNumbers = ->
sketch.More_Details_Text.visible = false
sketch.Less_Details_Text.visible = true
expandanimation1.start()

You just call the function in your app.coffee
changeNumbers()
This is executed whenever you open or reload your prototype.
This answer might be too simple but maybe you can explain your problem more if that doesn't help. Are you working in Framer Studio?

Related

How to build Unity WebGl via command line specifying Scene name?

I've a WebGl Unity application with some scenes.
I need to do a build for each scene, suppose SceneA, SceneB, SceneC...
So, to do build I wrote:
"C:\Program Files\Unity\Editor\Unity.exe" -buildTarget WebGL ... SceneName ?
Questions are:
How to specify SceneName ?
And how to specify destination directory ?
Thanks
Are you asking how to specify which scenes are used when making a build through the command line? If so, here's how I would go about it.
For your first question,
How to specify SceneName ?
I am unaware if you can directly specify scene names in the command line, but you can run specific functions using the command line that can change which scenes are built for the project.
Here is a snippet you would need but can change for your use case
using UnityEditor;
class MyEditorScript
{
static void PerformBuild ()
{
string[] scenes = { "Assets/MyScene.unity" };
BuildPipeline.BuildPlayer(scenes, ...);
}
}
The above snippet is quite simple, you specify each scene directly then add it to your build settings. You can pass in parameters to get different results or make multiple functions, whichever is easiest for you. Here is how you would call this function in the command line
"C:\Program Files\Unity\Editor\Unity.exe" -batchmode -executeMethod MyEditorScript.PerformBuild
I use -batchmode here so if any prompts are brought up, Unity will silence them so the process can be much more automated.
As for your second question,
And how to specify destination directory ?
I am not sure if you want to tie the directory where you save and the scenes you build with, but it might make everything easier. There is a build setting called BuildPlayerOptions.locationPathName, which allows you to specify where the build is save
static void WebGLProductionBuild()
{
// Build the player.\
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new[] { "Assets/Scene1.unity", "Assets/Scene2.unity" };
buildPlayerOptions.locationPathName = "yourLocationNameHere";
buildPlayerOptions.target = BuildTarget.WebGL;
buildPlayerOptions.options = BuildOptions.None; // set whatever you want here
BuildPipeline.BuildPlayer(buildPlayerOptions); // apply the setting changes
}
To call the above method is exactly the same except for the function call as the above line
"C:\Program Files\Unity\Editor\Unity.exe" -batchmode -executeMethod MyEditorScript.WebGLProductionBuild
I do not believe what you want to achieve can completely be done from command line, but this answer is pretty close. I am also not exactly sure if you wanted the scenes and the new path bundled together. If you are looking to build each individual scene and specify a new path, you can do so by making a new function with a switch statement or just make multiple functions to call.
Unity already provides answer to a similar question here.
You can create a method to make build validations, change settings and build different players. These methods have to be inside a script file located in an Editor folder, for example Assets/Editor/Builders/Builder.cs. The class also doesn’t need to extend any Unity class - the only requirement is that static functions are used.
using UnityEditor;
using System;
class Builder
{
static void Build ()
{
string[] arguments = Environment.GetCommandLineArgs();
// ... your code here, validations, flag changes, etc.
// foreach(string arg in arguments)
// Filter...
string sceneName = argument[1];
string destinationDirectoryPath = arguments[2];
// Build the player.\
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new[] { sceneName };
buildPlayerOptions.locationPathName = destinationDirectoryPath;
//buildPlayerOptions.target = "Your Target";
BuildPipeline.BuildPlayer(buildPlayerOptions);
}
}
You can then call the builder function using these command:
/Path/To/Unity -batchmode -executeMethod Builder.Build SceneName
DestinationDirectoryPath

Adding another function in an "App Designer" function

I'm using App Designer in MATLAB. I have created a push button, 51-54 work no problem, then when I assigned another function into it (highlighted in the screenshot), it wouldn't work!
Please help me overcome this problem.
Screenshot showing the problem:
Problem: function inside of a function the way it is written in the screenshot.
4 things come up my mind:
Generally:
yourApp.mlapp or any other code.m file
function someProcess()
end
function subProcess()
end
In your case rather try to write your function in an second .m file and call it from within your your app.
be sure to have it on the MATLAB path.
yourApp.mlapp or any other code.m file
function someProcess()
subProcess();
end
+ external code.m file
function someProcess()
subProcess();
end
define your function as a public or private function (method) inside the app. ( for others: the block is not there by default. click: app designer> code view > function > add private function | add public function)
screenshot
if your function is only used once you could also write an anonymous function
https://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html

How to get karma to run a init function first?

Ive got a weird problem, Ive got a JS library I pull down from a CDN, and before I can use it I need to run an init function on it, and then run my tests. Anyone got any ideas how I can do that?
In my actual project I call the init function first, then call the rest of my code from the inits callback, but I just cant figure out how to do this for a test
You can list CDNs in your karma config:
files : [
'http://theurl.totheserver/thelibrary.js',
Then assuming the library has initialization function that takes a callback function as a parameter:
describe("My tests", function() {
before(function(done) {
myLibrary.initialization(done);
});
describe("My test cases", function() {
However I would consider using Bower to manage your front end dependencies rather than relying on CDNs.

Creating multiple indexes using script

How do I create a multiple indexes using a script/file so that I can run it in the shell and create all the indexes in one action?
The info is listed here: http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/
Do I create a javascript file (.js) and just list all the ensureIndexes one after another like:
db.data1.ensureIndex(..)
db.data2.ensureIndex(..)
db.data3.ensureIndex(..)
db.data4.ensureIndex(..)
Is this syntactically correct? Is this going to compile?
Basically you are right.
You write a js function in a file
a = {}
a.b = function(){
db.coll.createIndex(<options>);
// do all other things
}
a.c = function(){
// something else
}
then load js
load("jsfile.js")
then execute your function a.b();
What problems do you have with your code? What do you mean by compile?

Which file contains function of core/session in magento?

I need to customize other's code,
so I found they used
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
in Order.php file for custom order email
so I can't find this function getMyCustomBlockInfo();
Can anyone tell me where this function reside?
Thanks
those are magic functions get() and set() and you are asking a session variable there that is set as
Mage::getSingleton('core/session')->setMyCustomBlockInfo();
somewhere in your code. If you use terminal you can easily find by making a following grep:
grep '>setMyCustomBlockInfo(' . -rsni
and it will list the files where your variable is set to session.
example :
Mage::getModel('catalog/product'); //or
Mage::getSingleton('catalog/product');
the code must be in '../app/core/Mage/Catalog/Model/Product.php' file
then
Mage::getSingleton('core/session');
the code must be in '../app/core/Mage/Core/Model/Session.php' file
because the class Mage_Core_Model_Session's parent::parent is Varien_Object, then you can do all magic functions and you can ->getData() to see the Data inside.
Mage::getSingleton('core/session')->getData();
on your problem when go call ->getData() you can see data : [my_custom_block_info]
you can set it with call
Mage::getSingleton('core/session')->setMyCustomBlockInfo('what');
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
// will return 'what'