Script working part of the time

Started by ponderitus, May 12, 2017, 06:16:53 PM

Previous topic - Next topic
May 12, 2017, 06:16:53 PM Last Edit: May 12, 2017, 06:18:31 PM by ponderitus
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) Select

local map = ...
local game = map:get_game()
local hero = map:get_hero()

if game:get_value("open_walk") then
  girl:set_visible(true)
  fake_girl:set_visible(false)
  else
  girl:set_visible(false)
  fake_girl:set_visible(true)

local npc_movement_2 = sol.movement.create("target")
  npc_movement_2:set_speed(64)
--  npc_movement_2:set_smooth(true)
  npc_movement_2:set_ignore_obstacles(true)
  npc_movement_2:set_target(girl)
  npc_movement_2:set_ignore_obstacles(true)
  npc_movement_2:start(fake_girl, function()
  girl:set_visible(true)
  fake_girl:set_visible(false)
  game:start_dialog("girl.down_here")
  game:set_value("open_walk", true)
end)
end

function girl:on_interaction()
    game:start_dialog("girl.hello")
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

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?).

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?

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.