Skip to content
User Avatar
#3677
Auto-translated
Martha

What could be the reason here? Why doesn't the check for the hero's name or their affiliation with the first player work in the second function?
Let me explain. QuestionBox passes the player number to the callback function (Portal_HaladF in your case) as the first argument, not the hero. It doesn't pass the hero at all. That's how the developers wrote it. Here's a solution:
 
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 - teleport, if no - offer Torost.
sleep(1)
else
print("not that hero");
end;
end;
Trigger(OBJECT_TOUCH_TRIGGER, "town_portal_Tilgatal", "Town_Portal_Tilgatal_Obelisk_F");

Then, we slightly modify the callback function, taking into account that the player is passed first

function Portal_HaladF (player,heroname)
local player = player + 0 -- I'm explaining a trick here. When you pass arguments directly in quotes, they are all passed as strings.
-- in player at the function's input, there's "1", and if you add zero to a string containing a number, it becomes a number (i.e., it will just be 1).
if(player == 1) then
SetObjectPosition(heroname, 56, 90, 0);
else
print("not that hero"); -- here, there's a check for the player, so it's more appropriate to write "not that player"
end;
end;

Now, let me explain what happened. You can pass arguments to the callback function manually (as in my example), but the standard argument passing is overwritten (I couldn't come up with a solution for this other than manually passing the parameters that the game was passing before. In this case, it's possible because only the player number is being passed). That is, we simply open the parentheses (yes, directly in quotes) and write the variables there. Important: numbers can be passed directly by simply specifying the variable in parentheses. This [["..heroname.."]] dinosaur is a way to pass a string. [[ ]] are also quotes. It's important that the quotes before the two dots match the quotes with which you open the
name of your function; otherwise, it won't work. This is a rather obscure thing, and it's worth reading about in Hottabych's guide.
P.S.
TalkBox would be suitable for your needs, but I'm afraid its use may cause difficulties.



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

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


                                                                                       

Statistics

Welcome our newest member: artem