if(input ~= "") then for i,v in pairs(Spring.GetTeamList()) do if v > 0 then -- a check because for some reason when i = 1, then v = 0 and teamID = nil local teamID = Spring.GetTeamList()[v] for j,k in pairs(Spring.GetTeamUnits(teamID)) do --k is unitID if k > 0 then --a check similar to above _,playerID,_,_,_,_,_,_=Spring.GetTeamInfo(teamID) playername,_,_,_,_,_,_,_,_,_=Spring.GetPlayerInfo(playerID) end end end end Spring.SendLuaUIMsg(msgbox.." Playername;"..playername..";Answer "..counter..";".." "..input) end
When i run its errors says: '[f=0000901] LuaUI::RunCallIn: error = 2, MouseRelease, [string "LuaUI/Widgets/gui_pausescreen.lua"]:213: attempt to concatenate global 'playername' (a nil value)'
Does anyone know what I am doing wrong? It works once before, but it doesn't now. I am connecting the 2 laptops through wireless.
Joined: 22 Feb 2006, 01:02 Location: cheap kitchen
This makes no sense:
Code:
for j,k in pairs(Spring.GetTeamUnits(teamID)) do --k is unitID if k > 0 then --a check similar to above _,playerID,_,_,_,_,_,_=Spring.GetTeamInfo(teamID) playername,_,_,_,_,_,_,_,_,_=Spring.GetPlayerInfo(playerID) end end
The variables of the loop are j and k. But nothing is done with them in the loop. Why do you loop over all units in a team if you just want a playername?
if k > 0 then --a check similar to above this a bit strange since unitIDs are always positive, so the check is unneeded. Use Spring.ValidUnitID (unitid) to see if a unitid is valid.
Also you get playername several times but SendLuaUIMsg is outside the loops, so only the last one will ever get send? What are you trying to do?
Am trying to get the playername. The player will be typing message on the screen, i want to add the playername to this message, after which sendluamessage to get another widget to write this message to a txt file.
Joined: 22 Feb 2006, 01:02 Location: cheap kitchen
Von66341 wrote:
The player will be typing message on the screen
in chat? in some textbox you made with lua? Why is that in gui_pausescreen.lua? help.
Since it is a widget the only player able to click the "send message" or whatever button is the local player. I would use Spring.GetMyPlayerID and pass that to GetTeamInfo
Also the funfact of SendMessage might be of interesst.
Yup. in a textbox i created in lua. is in gui_pausescreen.lua because the players are writing the message at gamepause, so i merge my textbox with the pausescreen widget.
I manage to get it working. my new code:
Code:
if(input ~= "") then if(playercount ==0) then for i,v in pairs(Spring.GetTeamList()) do if v > 0 then -- a check because for some reason when i = 1, then v = 0 and teamID = nil local teamID = Spring.GetTeamList()[v] _,playerID =Spring.GetTeamInfo(teamID) playername = Spring.GetPlayerInfo(playerID) Spring.Echo("playername") Spring.Echo(playername) playercount= playercount+1 break end end end end
if(playername == nil) then --Spring.Echo("nil") else --Spring.Echo("message") Spring.SendLuaUIMsg(msgbox.." Playername;"..playername..";Answer "..counter..";".." "..input) --Spring.Echo(msgbox.." Playername;"..playername..";Answer "..counter..";".." "..input) end input = "" end
Do you see if i might have any further problems with the code i write?
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum