...

View Full Version : New to JS, need script help!



GregJ822
07-18-2012, 02:32 PM
I am creating a script that runs from a program called MaxIm DL. I am new to javascript but am fairly decent at Java. The program only takes JS or VBS as scripting languages. My script is supposed to grab which camera filter the camera is currently using (got CCDCamera from their website) set it to a string, take it again 3 seconds later and set it to another string. then send it though a socket to the server.

I cant get the program to even run in command prompt because it opens and closes immediately. Any help on this would be great!

Here's my code: http://codeviewer.org/view/code:2823

oneguy
07-18-2012, 09:26 PM
Your code contains syntax errors.
Line 379:

function.prototype.run{
function is a keyword, it can't be used as an identifier. And unexpected { symbol. I don't know what you meant exactly but maybe this:


Function.prototype.run=function(){

Function is a built-in function and constructor.
Does your environment have a console which shows errors?

GregJ822
07-18-2012, 09:29 PM
I edited the old code, so the new code should be there now. consolidated it down. still doesnt run

oneguy
07-18-2012, 09:39 PM
Sorry, I left your code open many hours ago and answered only now and didn't notice that you changed the link. Now your code is syntactically valid and I have no idea why it doesn't run. Maybe it's a problem with your environment.

oneguy
07-18-2012, 09:43 PM
Your program has only variable and function declarations, so running it won't have any visible effect.

GregJ822
07-18-2012, 09:47 PM
Im using "1st javascript editor." ive ran it though command prompt and it closes instantly. Shouldnt it run for 3 seconds atleast?

oneguy
07-18-2012, 09:56 PM
Im using "1st javascript editor." ive ran it though command prompt and it closes instantly. Shouldnt it run for 3 seconds atleast?
No, if this is the full program, it with run and close instantly, because it has only variable and function declarations. The function getRawFilter calls setTimeout but it's never called itself.

GregJ822
07-18-2012, 09:56 PM
If im running it from localhost shoudnt it send it to the command line?

oneguy
07-18-2012, 09:59 PM
If im running it from localhost shoudnt it send it to the command line?
Sorry, I don't understand the question. What to send to the command line?

GregJ822
07-18-2012, 10:00 PM
If the host is localhost shouldn't it output whatever "changed" is to the command prompt? Do i need to call getRawFilter from another function in order for it to run?

oneguy
07-18-2012, 10:12 PM
Your program doesn't output anything. You declared 3 function but didn't call them. So the interpreter only wrote their code into memory but didn't execute them.

Do i need to call getRawFilter from another function in order for it to run?
Your need to execute this statement


getRawFilter();

You can add it to the program. If you add it to another function which won't be called, this statement won't be executed either.

Old Pedant
07-18-2012, 10:26 PM
On top of that, nowhere in that code do you define what CCDCamera is.

On top of that, nowhere do you invoke the run function.

On top of that...

Well, I really get the feeling we are seeing only a tiny part of your code.

GregJ822
07-18-2012, 10:27 PM
Here's what i did:

function run(){

function getRawFilter();

var socket = new JSocket();
var port = 3000;
var host = "localhost";

socket.onReady = function(){
socket.connect(host, port);
};

socket.onConnect = function(success, msg){
if(success){
//Send something to the socket
socket.write("connected");
}
else{
alert("Connection failed: " + msg);
}
socket.onData = function(data){
alert("Recieved from socket: " + data);
};
socket.setup("mySocket");
};

if(changed !== null){
socket.send(changed);
}
}

How would i call the run function now? do I need to make another function that just calls it?

GregJ822
07-18-2012, 10:34 PM
This script is being ran from inside another program which on their website says CCDCamera.FilterWheelName is the way to get the filter. Theres a pull down menu from where i can run this script inside of it, so would i even need to define CCDCamera?

GregJ822
07-18-2012, 10:40 PM
run[/b] function.



how would i invoke the run function? I dont think making another function to call it would do anything since that would just be a never ending chain of invoking methods

oneguy
07-18-2012, 11:07 PM
how would i invoke the run function?
Oh, since you came from Java, this explains the things. A Java program can contain in the higher level only package, import and class declarations, if I'm right. A Javascript program can contain any statements and function declarations in the higher level. Simply add the statement


run();

to the list of high-level statements in the program.

GregJ822
07-18-2012, 11:20 PM
great! thanks for all your help!

GregJ822
07-19-2012, 01:42 PM
Another problem:

I'm pretty sure i need to define CCDCamera even though i'm running it directly though the program. how would i do that? the program is called "MaxImDL" so would it be something to the effect

CCDCamera.MaxImDL?

Here's where i was getting the filter wheel name from http://www.cyanogen.com/help/maximdl/MaxIm-DL.htm#CCDCamera_Properties.htm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum