1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 Trying to index variable that is not an array

Discussion in 'Programming' started by Heathenlamb, Feb 11, 2019.

  1. Heathenlamb

    Heathenlamb Member

    Joined:
    Jul 14, 2016
    Posts:
    48
    Hey guys ... need your infinite wisdom once again. I am getting this error when I install the project on another pc.

    "Trying to index variable that is not an array ... alarm 0 line 4"

    So it only throws this error when I install it on another pc other than the one I am developing on. If I run it on my dev PC it runs fine without an issue. Here is the code -

    CREATE -
    Code:
    next = 0;
    vidpath = "C:\content/";
    count = 0;
    var i = 0;
    fileName = file_find_first_ns(vidpath+"*.mp4");
    
    while(fileName != "")
    {
        fArray[i] = fileName;
        fileName = file_find_next_ns();
        i += 1;
    }
    
    file_find_close_ns();
    vidcount = array_length_1d(fArray);
    result_init = video_init( window_device() );
    alarm_set(0, 1);
    

    ALARM 0 -
    Code:
    application_surface_enable( false );
    
    room_speed = 60;
    
    nextvideo = fArray[next]
    
    vidselect = vidpath + nextvideo
    
    result_load = video_load(vidselect);
    
    result_draw = 0;
    result_time = 0;
    result_duration = 0;
    video_surface = 0;
    
    video_set_loop(false);
    
    video_play()
    
    count = count + 1;
    
    alarm_set(2, 10);
    
    
    So it reads the mp4 content from a folder and puts the file names in an array, then uses that array to create a dynamic loopable playlist. As I said, it runs perfectly on the pc I use to develop the project. But when I install it on another pc I keep getting that error. I understand the nature of what it is saying but after staring at the code for days I simply can not work out what the hell is wrong. It is compiled with YYC.

    Any help or advice would be greatly appreciated.
     
    Last edited: Feb 11, 2019
  2. The Sorcerer

    The Sorcerer Member

    Joined:
    Jan 3, 2019
    Posts:
    147
    Are there any files in the folder in the other PC?

    Seems to me that if there are no files then fArray will never get defined.
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    3,559
    If the path does not exist on your other system, then fArray will never be set.

    Also, DO NOT post code in plain text or any manual styling, use [code] and [/code] tags. It is particularly important for your particular issue, because like many pieces involving the iteration of arrays, the character sequence [i] appears in the code. This interferes with the BBCode parser and corrupts the code you post. Right now, I cannot tell if you did this (correct):
    Code:
    fArray[i] = fileName;
    Or this (clearly incorrect):
    Code:
    fArray = fileName;
    Putting code between [code] and [/code] tags prevents the BBCode parser from acting on your code and preserves all tab spacing needed for reading indentations.
     
  4. Heathenlamb

    Heathenlamb Member

    Joined:
    Jul 14, 2016
    Posts:
    48
    Yes there are files on the other pc ... and yes the path does exist.

    I apologise about the code posting thing. I have been posting code on here for years and that is the first time I have heard about this ... OK ... all fixed !
     
  5. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    672
    It's been in the guidelines for years. You may need to repost your code again in code tags as it looks like it is still doing the italics as it was in your original post so it looks like fArray is not actually set up as an array:
    Code:
    fArray = fileName;
     
  6. Heathenlamb

    Heathenlamb Member

    Joined:
    Jul 14, 2016
    Posts:
    48
    Oh I am not disputing that it has been a rule for yrs. Just simply stating that I was never aware of it until now ... as far as I can tell the code is presenting properly now.

    So this is how it actually presents in the code now I have fixed it -

    Code:
    fArray[i] = fileName;
    
    Hence my frustration at why it is not working.
     
  7. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    672
    As has been mentioned by others, is there actually that folder "C:\content" on the other pc, and are there any .mp4 files in that folder on that pc. If not, then fArray will not get set with anything. Also, what is the file_find_first_ns function? I can't see that in the docs, so don't know what it is doing. Is it something to allow you to reference a folder outside the sandbox environment?
     
  8. Heathenlamb

    Heathenlamb Member

    Joined:
    Jul 14, 2016
    Posts:
    48
    Yes the folder is there and has files ... file_find_first_ns is a command from a non-sandboxed extension i have running in the project.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice