LUA scripts are not working

  • #1, by NormalUserTuesday, 06. October 2015, 14:22 9 years ago
    Hi there,
    I was just testing the LUA script functionality but for some reason it's not working.

    I have tried a Script under "Scripts" and also just print a string with Scene > Actions > At beginning of Scene > Execute Script > print("test")

    I checked if the Help > Log-Window shows anything but it does not.

    What am i missing?

    Regards

    Newbie

    24 Posts


  • #2, by afrlmeTuesday, 06. October 2015, 14:30 9 years ago
    The log window found under help > log is actually the editor log file.

    Press TAB on your keyboard while running your game through the editor to open up the developer console. Type: print log & then press enter. You can navigate the log pages with the page up / down keys on your keyboard.

    Alternatively you can try to locate the actual log file on your hard drive. It is usually somewhere in c:/users/username/appdata/local/... If you want the actual location then you can use the developer console to find it.

    Open up developer console with TAB, then type: exec print(localAppDir) then press enter. Next type print log & press enter again to show the log then look through the log for a line that starts with c:/users/... & that should be where the log files & save games are being stored for the project you have open.

    P.S: the runtime log is called messages.txt or messages.log.

    Imperator

    7285 Posts

  • #3, by NormalUserTuesday, 06. October 2015, 14:36 9 years ago
    thanks AFRLme, you are already my best friend here. grin

    *edit: It works. One important thing to notice, you have to change the LOG Level to "Info" otehrwise the print output is not logged. (In the options Player tab)

    Newbie

    24 Posts

  • #4, by afrlmeTuesday, 06. October 2015, 14:47 9 years ago
    Yes. Info allows the engine to print everything to the log from warnings to errors to manually created log messages through the print() function.

    Did you check the link to that thread I mentioned yesterday night in your other thread? It contains various tips on improving user experience on VS.

    Imperator

    7285 Posts

  • #5, by NormalUserTuesday, 06. October 2015, 14:59 9 years ago
    Yeah checked it. I saw the log mentioned there as well, i just wanted to make sure the next person wondering why the print is not visible knows why.

    Newbie

    24 Posts

  • #6, by NormalUserTuesday, 06. October 2015, 15:09 9 years ago
    Any idea what's wrong with this?

    function scene_overview ()
    
     local gx = game.WindowResolution.x
     local gy = game.WindowResolution.y
    
    print("x: " .. gx .. " y: " .. gy )
    
    game.GameScrollToPoint({x=gx, y=gy})
    
    end
    


    I get:
    3:05:14 PM: x: 1280 y: 720
    3:05:14 PM: [string "functions"]:9: attempt to call field 'GameScrollToPoint' (a table value)
    3:05:14 PM: stack traceback:
    [string "Map1: At beginning of scene: Execute script '..."]:5: in function 'GameScrollToPoint'
    [string "functions"]:9: in function 'scene_overview'
    [string "Map1: At beginning of scene: Execute script '..."]:2: in function
    [C]: in function 'xpcall'
    [string "Map1: At beginning of scene: Execute script '..."]:1: in main chunk


    *edit: Works like this:
    game:setValue(VGameScrollToPoint, {x=gx, y=gy})

    Newbie

    24 Posts

  • #7, by afrlmeTuesday, 06. October 2015, 15:27 9 years ago
    Yeah because you have incorrectly used the new shorthand scripting method which unfortunately is currently undocumented due to there being multiple names you can use instead of the full field / table names.

    Also you tried to execute a function() that doesn't exist. You update fields / tables with a single = symbol. 2 == symbols are for when you want to query if x == y etc.
    game.ScrollToPoint = {x = gx, y = gy}
    

    Imperator

    7285 Posts

  • #8, by NormalUserTuesday, 06. October 2015, 16:17 9 years ago
    I edited the above post, i guess you didn't notice. I got it working with the old syntax. Thx anyway

    Is there any kind of event fired when the ScrollToPoint reaches it's desination?
    I am trying to fly through the map. For that i need to know when teh first destination is reached and then fire ScrollToPoint again to get to the next desination.

    I tried it like this but all i get is a black screen and an endlessly running loop. wink


    function scene_overview ()
    
     	local gx = game.WindowResolution.x
     	local gy = game.WindowResolution.y
    	local waypoint = 0
    
    	while waypoint < 4 do
    		scroller =  game:getBool(VGameScrollTo)
    		if not scroller then
    		    if waypoint == 0 then
    			waypoint = 1
    			game:setValue(VGameScrollToPoint, {x=0, y=gy})
    		    elseif waypoint == 1 then
    			waypoint = 2
    			game:setValue(VGameScrollToPoint, {x=gx, y=gy})
    		    elseif waypoint == 2 then
    			 waypoint = 3
    			 game:setValue(VGameScrollToPoint, {x=gx, y=0})
    		    elseif waypoint == 3 then
    			waypoint = 4
    			game:setValue(VGameScrollToPoint, {x=0, y=0})
    		    end
    		end
    	end
    end
    


    Newbie

    24 Posts

  • #9, by afrlmeTuesday, 06. October 2015, 16:40 9 years ago
    Yes I noticed your edit before I replied. I was correcting & providing some insight into the shorthand Lua script method.

    Fly through the map? Could you please provide me with a screenshot & some more details please.

    Also I don't recommend using while or repeat Lua loops with VS, they often end up crashing the engine due. I think maybe due to looping faster than the engine / system can handle.

    Anyway... why are you trying to script it?

    Imperator

    7285 Posts

  • #10, by NormalUserTuesday, 06. October 2015, 16:49 9 years ago
    As i said, nothing special and it's just me learning lua and VS.
    I am trying to scroll to more than one point of a scene:

    When i add two:
    Scene > Scroll Scene to Point

    they will both executed at the same time. But i want them executed one by one.

    Newbie

    24 Posts

  • #11, by afrlmeTuesday, 06. October 2015, 17:07 9 years ago
    Ok dokie. You remember that I mentioned the scroll position is based on the top left pixel yes?

    I see there is no wait until scroll finished option or action part available. I guess you will have to create a loop then.

    Ok so create an execute a script action part...
    local function scrollTo()
     if not game.ScrollTo then
      if game.ScrollPosition == { x = 0, y = 0 } then game.ScrollToPoint = { x = 300, y =  0 }
      elseif game.ScrollPosition == { x = 300, y = 0 } then game.ScrollToPoint = { x = 0, y = 0 }; unregisterEventHandler("mainLoop", "scrollTo")
      end
     end
    end
    
    registerEventHandler("mainLoop", "scrollTo")
    

    ... not a finished example but it gives you an idea on how to create a loop, how to make it move somewhere, how to check when position is same as last specified position & how to unregister the loop. Hope this helps. Good luck! wink

    Imperator

    7285 Posts