Skip to content
User Avatar
#3679
Auto-translated
Martha
Unfortunately, it doesn't work. The game displays:

[Script Warning!] Walue was NIL when getting global with name 'player'
Script Error: attempt to perform arithmetic on a nil value

P.S. I don't even know what TalkBox is.
Perhaps I made a mistake somewhere. I will test it myself now and send it to you.

UPDATE:
Indeed, there was an issue with the player, which I have now fixed. Below is the fully working code snippet, tested by me.
All you have to do is add the same "dance" with [[ ]] to the player. I will say one thing: in your case, the second check is redundant. If you are only showing a message to one player, there is no point in even checking in the portal function whether it is the first player, because he is already the only one. But complete it with passing the player so that you understand how it works in the future. But in the code itself, as you can see, it is not needed.
SetObjectEnabled("testObj",nil)
Trigger(OBJECT_TOUCH_TRIGGER,"testObj","testF")
function testF(heroname)
local player = GetObjectOwner(heroname);
if(player == 1) then
QuestionBox(GetMapDataPath().."messages/broken_portal.txt","callbackF([["..player.."]],[["..heroname.."]])","callback_noF([["..player.."]],[["..heroname.."]])") -- arbitrary message from my folder.
end;
end;
function callbackF(player,heroname)
local x,y,floorID = GetObjectPosition(heroname) -- For testing, the hero is simply teleported to the same location
SetObjectPosition(heroname,x,y,floorID)
end;

function callback_noF(player,heroname)
local x,y,floorID = GetObjectPosition(heroname)-- For testing, the hero is simply teleported to the same location + 5 cells along all axes
SetObjectPosition(heroname,x+5,y+5,floorID)
end

Below is your already corrected code

function Town_Portal_Tilgatal_Obelisk_F (heroname) 
local player = GetObjectOwner(heroname)
if(player == 1) then
QuestionBox("/Maps/SingleMissions/L1/Portal_Halad.txt", "Portal_HaladF([["..player.."]],[["..heroname.."]])", "Town_Portal_Torost_question_F([["..player.."]],[["..heroname.."]])"); ----question: do you want to go to Halad? If yes - we teleport, if not - we offer Torost.
sleep(1)
else
print("not that hero");
end;
end;
Trigger(OBJECT_TOUCH_TRIGGER, "town_portal_Tilgatal", "Town_Portal_Tilgatal_Obelisk_F");
function Portal_HaladF (player,heroname)
SetObjectPosition(heroname, 56, 90, 0);
end;

I hope it works. My head isn't working well tonight - I apologize if there is some stupid mistake, check the logic of what is happening five times just in case :)



Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       

Statistics

Welcome our newest member: artem

Users Online 4 users 1619 guests