Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    New to JS, need script help!

    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
    Last edited by GregJ822; 07-18-2012 at 03:21 PM. Reason: updated code

  • #2
    New Coder
    Join Date
    Jul 2012
    Location
    Ukraine
    Posts
    71
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Your code contains syntax errors.
    Line 379:
    Code:
    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:
    Code:
    Function.prototype.run=function(){
    Function is a built-in function and constructor.
    Does your environment have a console which shows errors?
    Last edited by oneguy; 07-18-2012 at 08:32 PM.

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I edited the old code, so the new code should be there now. consolidated it down. still doesnt run

  • #4
    New Coder
    Join Date
    Jul 2012
    Location
    Ukraine
    Posts
    71
    Thanks
    1
    Thanked 18 Times in 17 Posts
    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.

  • #5
    New Coder
    Join Date
    Jul 2012
    Location
    Ukraine
    Posts
    71
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Your program has only variable and function declarations, so running it won't have any visible effect.

  • #6
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Im using "1st javascript editor." ive ran it though command prompt and it closes instantly. Shouldnt it run for 3 seconds atleast?

  • #7
    New Coder
    Join Date
    Jul 2012
    Location
    Ukraine
    Posts
    71
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Quote Originally Posted by GregJ822 View Post
    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.

  • #8
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    If im running it from localhost shoudnt it send it to the command line?

  • #9
    New Coder
    Join Date
    Jul 2012
    Location
    Ukraine
    Posts
    71
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Quote Originally Posted by GregJ822 View Post
    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?

  • #10
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #11
    New Coder
    Join Date
    Jul 2012
    Location
    Ukraine
    Posts
    71
    Thanks
    1
    Thanked 18 Times in 17 Posts
    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
    Code:
    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.
    Last edited by oneguy; 07-18-2012 at 09:16 PM.

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #13
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #14
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #15
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    [QUOTE

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

    [/QUOTE]

    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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •