| 10-18-2010, 06:40 AM | #1 |
I was reading up about Zinc and a lot of things appealed to me a whole lot more than coding in vJASS, so I thought I'd give it a try. I started off with what I thought would be a simple trigger, using operators and structs to store a players name in a more OOP-like manner. Here's what I came up with: Zinc:
library Init {
public playersData Players;
struct playersData{
playerData Player [10];
method operator [](player p) -> playerData {
return Player[GetPlayerId(p)];
}
}
struct playerData{
string Name = "";
}
function onInit() {
integer x;
Players = playersData.create();
for ( 0 <= x < 11){
Players[Player(x)].Name = GetPlayerName(Player(x));
}
}
}
library onTalk {
function onTalk(){
player p = GetTriggerPlayer();
BJDebugMsg(Players[p].Name);
}
function onInit() {
trigger t = CreateTrigger();
integer x = 0;
for ( 0 <= x < 11){
TriggerRegisterPlayerChatEvent(t, Player(x), "", false);
}
TriggerAddAction(t, function onTalk);
}
}
Now the intention of this is to return the players name using the handy new OOP system whenever he or she speaks. But it does not... instead it outputs the name of the last player setup (player 11 in this case). This suggests that the playerData array is just overwriting itself. I thought it might be because I hadn't used ".create()" for the playerData struct, but when I try to make the playersData struct like this: Zinc:struct playersData{ playerData Player [10]; method operator [](player p) -> playerData { return Player[GetPlayerId(p)]; } static method onInit() { integer x; for ( 0 <= x < 11){ Player[x] = playerData.create(); } } } It throws and error declaring "Undeclared variable this" on the line set s___Init___playersData_Player[s__Init___playersData_Player[this]+x]=s__Init___playerData__allocate() If anyone could point me in the right direction I'd be eternally grateful. |
| 10-18-2010, 01:07 PM | #2 |
Hmnn, your syntax error is because you are using a non-static member inside a static method. Yeah , I think it should detect those errors before converting the code... But it does not, so we'll have to live with it. Just declare the "Player" array member as static. |
