Game Development Asked by Fence_rider on December 8, 2021
I’m trying to build a mod that places zones on a keypress. How would I accomplish this?
So far I’ve detected the keypress. But when I modify m_blocks in ZoneManager by calling block.setZone(x,y,zone) The block appears to have changed, but only for the moment. When I run the keycommand again, the data appears to have been reset. I never see the zone change in game, only when I print it to the console.
string outtext = "";
uint blockCount = Singleton<ZoneManager>.instance.m_blocks.m_size;
outtext += "start{n";
for (int index = 0; index < blockCount; index++) {
var block = Singleton<ZoneManager>.instance.m_blocks.m_buffer[index];
if (block.m_valid != 0) {
block.SetZone(1, 1, ItemClass.Zone.Industrial);
block.RefreshZoning(0);
outtext += " valid:" + block.m_valid + " position:" + block.m_position.ToString() + " zone:" + block.GetZone(1, 1) + " n ";
}
}
outtext += "}";
Debug.Log("OUTTEXT " + outtext);
I’ve tried calling block.refreshZoning() as well, but I’m not sure how to calculate the blockid :(.
The problem was that the equals operator does a deepcopy. I was able to fix this by forcing it to use a reference. This took forever to find out!
string outtext = "";
uint blockCount = Singleton<ZoneManager>.instance.m_blocks.m_size;
outtext += "start{n";
for (int index = 0; index < blockCount; index++) {
ref var block = ref Singleton<ZoneManager>.instance.m_blocks.m_buffer[index];
if (block.m_valid != 0) {
block.SetZone(1, 1, ItemClass.Zone.Industrial);
block.RefreshZoning(0);
outtext += " valid:" + block.m_valid + " position:" + block.m_position.ToString() + " zone:" + block.GetZone(1, 1) + " n ";
}
}
outtext += "}";
Debug.Log("OUTTEXT " + outtext);
Answered by Fence_rider on December 8, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP