Javascript questions

  • Luckily I have actually started using Javascript a couple of months ago. but I'm still an absolute beginner at it. So I have a couple of simple questions.

    What I'm trying to do is clear an array (as the input may have varying lengths), get a string split and put it in said array and then get the arrays length and put it in a global number.

    But what is throwing me for a loop is how to actually access said values and arrays. as they are a global values and an array object. Like I said. total beginner.

    Tagged:

  • I moved this to the scripting section.

    It would probably be easier to help if you shared your code so far - have you got something written and you're stuck about what to do next? Or are you asking about where to start?

  • thanks Ashley,

    the problem is more that my code is probably not making any sense as I do not know how to access other parts. what I'm doing is as following

    function stringSplit(){

    var x = inputString.value.toLowerCase();

    CommandArray = x.split(' ');

    }

    inputstring is a global string. CommandArray is an Array object. and I'm activating this script in block ( which as I just thought of won't even call the code as of now)

    but I might have been looking for answers in the wrong spot, as I was trying to search through the How do I?.. forum

  • It looks OK so far, just make sure CommandArray is declared somewhere first (e.g. let CommandArray;) since you can't assign to a variable that doesn't exist. Assuming you've done that, then you can just use CommandArray like an array.

  • That's just the problem. I know that I need to define it before I can assign values. but how do I assign it to this array.

    that's what I'm having trouble with understanding.

  • I think as of right now the Array interface has not been defined from the scripting API (at least not in the documentation) so you can't directly manipulate the array properties from javascript. You would need to call a function in the script that would callback into the eventsheet to manipulate the object.

  • Allright. I'm following so far. Does this mean I also can't access the global variables in the event sheet? And if so, what would be the workaround for these cases?

    I understand what you mean, I just haven't a single clue as to how I would do that.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here is a very basic example of the flow I described,

    drive.google.com/open

    the function splitString takes a string splits it then uses the runtime to call a function on the event sheet to populate the ArrayObject

    after that you can use the array how ever you want. hopefully this helps

  • this is amazing piranha, a very clear example of how to do this, thanks a lot!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)