Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Pages: 1
InitParse.cs is a tool created by processor supposed to be 'the best deserializer', but a lot of people seem to be having issues, so i'll help...
REMEMBER: This is an example and should not be argured with comments like:
'Noob example, get better C# skills.', 'This guide sucks', etc.
1. Setting up
To setup, copy the text from https://gist.github.com/Yonom/3c9ebfe69b1432452f9b
to your clipboard. (You can do this by using CTRL+C)
Now we need somewhere to paste this:
For this, make a new class (Do this by double clicking YourProjectName.csproj in VS
and pressing Add button, and then search Class and add it named as
InitParse.cs)
2. Integrating
After set up, you must make InitParse.cs work in your bot:
To do this, you will have to go in your code to where init's code is loaded, or, Message Handler, "init".
The example code fits perfectly:
var roomData = new uint[2, m.GetInt(12), m.GetInt(13)];
var chunks = InitParse.Parse(m);
foreach (var chunk in chunks)
{
foreach (var pos in chunk.Locations)
{
roomData[chunk.Layer, pos.X, pos.Y] = chunk.Type;
}
}
But if you are like me and madiik, you will want to turn roomData public.
To do this, you will have to add an uint[,,] blocks; in variables and replace the example code with this:
blocks = new uint[2, m.GetInt(12), m.GetInt(13)];
var chunks = InitParse.Parse(m);
foreach (var chunk in chunks)
{
foreach (var pos in chunk.Locations)
{
blocks[chunk.Layer, pos.X, pos.Y] = chunk.Type;
}
}
3. Specials
Now that you're done with making roomData public, you may want
to be able to access specials' subparammeters:
ID,TARGET and VALUE.
If your codestyle is more doing this:
blockargs[0, x, y][1] or SpecialVal(blockargs[0, x, y], 1)
rather than this:
WorldBlocks[x, y].Special1
Then use 1st way, or else, use 2nd way.
1st way. Object[,,]
For that, you will need to modify "init" a bit, but first, add to variables:
object[object[,,]] blockargs;
Now, "init":
blocks = new uint[2, m.GetInt(12), m.GetInt(13)];
blockargs = new object[object[2, m.GetInt(12), m.GetInt(13)]];
var chunks = InitParse.Parse(m);
foreach (var chunk in chunks)
{
foreach (var pos in chunk.Locations)
{
blocks[chunk.Layer, pos.X, pos.Y] = chunk.Type;
blockargs[chunk.Layer, pos.X, pos.Y] = chunk.args;
}
}
You are done, but like most, you may want to know: 'How do i use it?'.
Let's make one void(string): "SpecialVal", right below 'public Form1()'
public void SpecialVal(int pos, object block)
{}
This void will check for a special value according to 'pos' in block 'block'.
SpecialVal() will return null if no special in pos or block doesn't exist.
Let's code it.
public string SpecialVal(int pos, object[,,] block)
{
if (block != null)
{
return block[pos].ToString()
}
else
{
return null;
}
return null;
}
'How do i use it?' SpecialVal(int pos, object block)
e.g:
if Convert.ToInt32((SpecialVal(1, blockargs[[0, 15, 15]]))) == 3 then // blockargs[layer,x,y] would return object[objectWeWant].
{ // Let's pretend that in this case, blockargs[[0, 15, 15]] is a portal
//code
}
2nd way. Class WorldBlocks{}
The first thing you are gonna do is type the following below public Form1():
public partial class WorldBlock
{
public int BlockID { get; set; }
public int X { get; set; }
public int Y { get; set; }
public string Special1 { get; set; }
public string Special2 { get; set; }
public string Special3 { get; set; }
}
Now, go to you're variables and type:
public static WorldBlock[,] WorldBlocks;
After this, we need to define WorldBlocks. For that, go to "init" and add the following below blocks = (...):
WorldBlocks = new WorldBlock[m.GetInt(12), m.GetInt(13)];
Now you will need to define WorldBlocks values. For that, let's edit "init" again:
blocks = new uint[2, m.GetInt(12), m.GetInt(13)];
WorldBlocks = new WorldBlock[m.GetInt(12), m.GetInt(13)];
var chunks = InitParse.Parse(m);
foreach (var chunk in chunks)
{
foreach (var pos in chunk.Locations)
{
blocks[chunk.Layer, pos.X, pos.Y] = chunk.Type;
WorldBlocks[pos.X, pos.Y].BlockID = Convert.ToInt32(chunk.Type);
WorldBlocks[pos.X, pos.Y].X = Convert.ToInt32(pos.X);
WorldBlocks[pos.X, pos.Y].Y = Convert.ToInt32(pos.Y);
if (chunk.Args.Length >= 1) {WorldBlocks[pos.X, pos.Y].Special1 = chunk.Args[1].ToString();}
if (chunk.Args.Length >= 2) {WorldBlocks[pos.X, pos.Y].Special2 = chunk.Args[2].ToString();}
if (chunk.Args.Length >= 3) {WorldBlocks[pos.X, pos.Y].Special3 = chunk.Args[3].ToString();}
}
}
Error Hotfix:
If you are getting this error:
, then make sure InitParse.cs line 6 doesn't say namespace Yonom.EE.
If it does, then replace it with namespace [YOUR Form1.cs text after namespace].
Offline
For this, make a new class (Do this by double clicking R42Bot++.csproj in VS
I don't want your bot thx. But this should help out people who are having trouble.
thanks zoey aaaaaaaaaaaand thanks latif for the avatar
Offline
For this, make a new class (Do this by double clicking R42Bot++.csproj in VS
I don't want your bot thx. But this should help out people who are having trouble.
oh lol sorry diddn't notice xD
anyways thanks for your feedback
Offline
A note to be added is that a uint wouldn't store the block's parameters.
So they have to make a class RoomData or something with an object[] args/object[] params;
So they can get the args from the chunks.
That is, if they had to use rotations and extra data though I doubt many would.
Offline
A note to be added is that a uint wouldn't store the block's parameters.
So they have to make a class RoomData or something with an object[] args/object[] params;
So they can get the args from the chunks.
That is, if they had to use rotations and extra data though I doubt many would.
I'll add a step in guide for that.
Offline
public string SpecialVal(int pos, object block)
{
if (block != null)
{
if (block[pos] != null)
{
return block[pos].ToString()
}
else
{
return null;
}
}
else
{
return null;
}
return null;
}
Cannot apply indexing with [] to an expression of type 'object'
Are you sure you tested this?
Also, made a fix to your WorldBlock class.
public partial class WorldBlock
{
public int BlockID;
public int X;
public int Y;
public string Special1;
public string Special2;
public string Special3;
}
shh i have returned
Offline
public string SpecialVal(int pos, object block) { if (block != null) { if (block[pos] != null) { return block[pos].ToString() } else { return null; } } else { return null; } return null; }
Cannot apply indexing with [] to an expression of type 'object'
Are you sure you tested this?
Also, made a fix to your WorldBlock class.
public partial class WorldBlock { public int BlockID; public int X; public int Y; public string Special1; public string Special2; public string Special3; }
Lol, i haven't tested it at all!
Try now, i noticed two errors i haven't noticed while coding:
object[,,] blockargs;
(...)
blockargs = new uint[...] // yup. OBJECT[,,] as uint. srs
SpecialVal(int pos, object block)
{
...
block[pos] // wait, i tought block was not an array?
}
It's fixed, so now your code must work.
Also please, don't try the two ways, just try your codestyle.
Offline
It's fixed, so now your code must work.
Also please, don't try the two ways, just try your codestyle.
I tried using one of them, by testing one of them and using the second one later
EDIT: May I also state Processor uses .Args not .args? It's with a capital "A."
Your function still doesn't work, SpecialVal fails.
Also, I did everything exactly to the manual of 1st way.
I tried to edit the function:
public string SpecialVal(int x, int y, object[,] blockargs)
{
if (blockargs != null)
{
if (blockargs[x,y] != null)
{
return blockargs[x,y].ToString();
}
else
{
return null;
}
}
else
{
return null;
}
}
then //blockargs[0,
a lil' bit of lua?
shh i have returned
Offline
public partial class WorldBlock
{
public int BlockID;
public int X;
public int Y;
public string Special1;
public string Special2;
public string Special3;
}
why not do:
public partial class WorldBlock
{
public int BlockID;
public int X;
public int Y;
public object[] args;
}
public List<WorldBlock> worldblocks = new List<WorldBlock>();
if(m.Type == "init")
{
var chunks = InitParse.Parse(m);
foreach (var chunk in chunks)
{
foreach (var pos in chunk.Locations)
{
worldblocks.Add(new WorldBlock{FILL IN EASY REQUIREMENTS, args=c.Args});
}
}
}
If you would like me to make a bot for you, go here.
Offline
madiik wrote:public partial class WorldBlock
{
public int BlockID;
public int X;
public int Y;
public string Special1;
public string Special2;
public string Special3;
}why not do:
public partial class WorldBlock { public int BlockID; public int X; public int Y; public object[] args; } public List<WorldBlock> worldblocks = new List<WorldBlock>(); if(m.Type == "init") { var chunks = InitParse.Parse(m); foreach (var chunk in chunks) { foreach (var pos in chunk.Locations) { worldblocks.Add(new WorldBlock{FILL IN EASY REQUIREMENTS, args=c.Args}); } } }
What if I want to access if like an array, for example...
if (World[0, x, y] == 9)
shh i have returned
Offline
you still have your old array, with the block data in it. The list is for replacing and such like if you wanna go through all blocks placed and replace only id 9 blocks, instead of cycling through every possible location with two for loops, one foreach loop will circle through only the blocks placed, making the time shorter and more efficient.
If you would like me to make a bot for you, go here.
Offline
Jabatheblob1 wrote:madiik wrote:public partial class WorldBlock
{
public int BlockID;
public int X;
public int Y;
public string Special1;
public string Special2;
public string Special3;
}why not do:
public partial class WorldBlock { public int BlockID; public int X; public int Y; public object[] args; } public List<WorldBlock> worldblocks = new List<WorldBlock>(); if(m.Type == "init") { var chunks = InitParse.Parse(m); foreach (var chunk in chunks) { foreach (var pos in chunk.Locations) { worldblocks.Add(new WorldBlock{FILL IN EASY REQUIREMENTS, args=c.Args}); } } }
What if I want to access if like an array, for example...
if (World[0, x, y] == 9)
Updated using Visual Studio. Eh, it seems like i really do forgot things while coding.
2nd way. object is perfect
1st way. eww wtf you did everything different
fixed according to VS testing.
Offline
This could be useful! Thanks for spending the time making this <3
A quick fix to your WorldBlocks parser, lines 12-14:
if (chunk.Args.Length >= 1) WorldBlocks[pos.X, pos.Y].Special1 = chunk.Args[1].ToString();
if (chunk.Args.Length >= 2) WorldBlocks[pos.X, pos.Y].Special2 = chunk.Args[2].ToString();
if (chunk.Args.Length >= 3) WorldBlocks[pos.X, pos.Y].Special3 = chunk.Args[3].ToString();
I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.
Offline
if (World[0, x, y] == 9)
You still have that array, what i do is i keep an array:
int[,,] blocks = new int[2,Width,Height];
and a list of blocks
List<block> blockL = new List<block>();
If you would like me to make a bot for you, go here.
Offline
marcoantonimsantos wrote:if (World[0, x, y] == 9)
You still have that array, what i do is i keep an array:
int[,,] blocks = new int[2,Width,Height];
and a list of blocks
List<block> blockL = new List<block>();
Well it would do no difference (in envroiment meaning, not code saving), but, this is an example, you can do it your way.
Offline
i find it easier to have both for certain cases, but you do you
If you would like me to make a bot for you, go here.
Offline
Pages: 1
[ Started around 1732812155.3825 - Generated in 0.219 seconds, 12 queries executed - Memory usage: 1.72 MiB (Peak: 1.96 MiB) ]