Author Topic: Script working part of the time  (Read 506 times)


  • Newbie
  • *
  • Posts: 33
    • View Profile
Script working part of the time
« on: May 12, 2017, 06:16:53 pm »
Hey, I've tried to make a simple npc script, but for some reason it only seems to work half the time....i can load the map and it will work....then literally close and re-open the console and it wont work anymore...then next time it might. It seems like it works about 20% of the time, can anyone tell me the reason for this? Just trying to make her walk at the 1st time on the map up to her point she will be at for the rest of the game and freeze the hero until she is there and has spoken her initial dialog, its the interaction bit at the end which seems to be failing i should mention

Code: Lua
  1. local map = ...
  2. local game = map:get_game()
  3. local hero = map:get_hero()
  5. if game:get_value("open_walk") then
  6.   girl:set_visible(true)
  7.   fake_girl:set_visible(false)
  8.   else
  9.   girl:set_visible(false)
  10.   fake_girl:set_visible(true)
  12. local npc_movement_2 = sol.movement.create("target")
  13.   npc_movement_2:set_speed(64)
  14. --  npc_movement_2:set_smooth(true)
  15.   npc_movement_2:set_ignore_obstacles(true)
  16.   npc_movement_2:set_target(girl)
  17.   npc_movement_2:set_ignore_obstacles(true)
  18.   npc_movement_2:start(fake_girl, function()
  19.   girl:set_visible(true)
  20.   fake_girl:set_visible(false)
  21.   game:start_dialog("girl.down_here")
  22.   game:set_value("open_walk", true)
  23. end)
  24. end
  26. function girl:on_interaction()
  27.     game:start_dialog("girl.hello")
  28. end

I also wanted to make the hero freeze on map start until this quest but I haven't been able to make that function yet, i know its hero:freeze() then hero:unfreeze()

I moved the end at line 24 to 29 and that seemed to help a little but it's still failing about 60% of the time
« Last Edit: May 12, 2017, 06:18:31 pm by ponderitus »


  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Script working part of the time
« Reply #1 on: May 13, 2017, 03:03:56 am »
I'm not following the steps you are doing for the scenario where it does not work. You say that it works the first time, but it should only work once period. After one successful run, are you opening the console to set the value of open_walk back to false? And then you leave the map and come back?

It's not clear to me which lines of the script are working as expected and which are not. The script does everything correctly except for initiating the "girl.down_here" dialog? It may be helpful to add some debug print statements to see if any lines aren't executing (for example, does the movement finish and execute the callback function you defined?).


  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Script working part of the time
« Reply #2 on: May 13, 2017, 03:31:52 am »
sorry, what i meant is if i test the script once it may work, then the next time i test it (after making no changes) it won't work. then next time it may or may not again.

how do i add debug print statements?


  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Script working part of the time
« Reply #3 on: May 13, 2017, 05:30:05 am »
I think i got it, the problem I think was that I was setting the npc to visible true/false rather than enabled so when I was trying to interact with the npc it was 50/50 whether the invisible or the real npc was being interacted with. since changing to enabled I've tested it 5 times and its worked all 5.