Official Everybody Edits Forums

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.

#1 2015-03-30 20:42:31, last edited by realmaster42 (2015-04-04 15:10:21)

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

[Guide] [C#] Using InitParse.cs

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:
hMxYWwn.png
, 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].


http://i.imgur.com/bjvgH5L.png?1

Offline

#2 2015-03-30 21:47:34

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: [Guide] [C#] Using InitParse.cs

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.


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

Wooted by: (2)

#3 2015-03-30 21:52:53

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: [Guide] [C#] Using InitParse.cs

Xfrogman43 wrote:

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 //forums.everybodyedits.com/img/smilies/tongue


http://i.imgur.com/bjvgH5L.png?1

Offline

#4 2015-03-31 11:26:08

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: [Guide] [C#] Using InitParse.cs

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

#5 2015-03-31 13:06:36, last edited by realmaster42 (2015-03-31 13:33:48)

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: [Guide] [C#] Using InitParse.cs

DarkDragon4900 wrote:

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.


http://i.imgur.com/bjvgH5L.png?1

Offline

#6 2015-04-03 22:10:13, last edited by madiik (2015-04-03 22:28:55)

madiik
Member
From: floor above Yuuta
Joined: 2015-02-26
Posts: 514

Re: [Guide] [C#] Using InitParse.cs

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

#7 2015-04-04 02:27:42

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: [Guide] [C#] Using InitParse.cs

madiik wrote:
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! //forums.everybodyedits.com/img/smilies/tongue
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.


http://i.imgur.com/bjvgH5L.png?1

Offline

#8 2015-04-04 08:15:38, last edited by madiik (2015-04-04 08:37:02)

madiik
Member
From: floor above Yuuta
Joined: 2015-02-26
Posts: 514

Re: [Guide] [C#] Using InitParse.cs

marcoantonimsantos wrote:

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 //forums.everybodyedits.com/img/smilies/smile

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;
              }
        }
marcoantonimsantos wrote:

then //blockargs[0,

a lil' bit of lua?


shh i have returned

Offline

#9 2015-04-04 09:05:31

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: [Guide] [C#] Using InitParse.cs

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});
       }
}

}

If you would like me to make a bot for you, go here.

Offline

#10 2015-04-04 10:14:16

madiik
Member
From: floor above Yuuta
Joined: 2015-02-26
Posts: 514

Re: [Guide] [C#] Using InitParse.cs

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)

shh i have returned

Offline

#11 2015-04-04 10:15:36

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: [Guide] [C#] Using InitParse.cs

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

#12 2015-04-04 11:48:16

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: [Guide] [C#] Using InitParse.cs

madiik wrote:
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.


http://i.imgur.com/bjvgH5L.png?1

Offline

#13 2015-04-04 14:11:29

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: [Guide] [C#] Using InitParse.cs

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

Wooted by:

#14 2015-04-04 20:12:34

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: [Guide] [C#] Using InitParse.cs

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>();


If you would like me to make a bot for you, go here.

Offline

#15 2015-04-04 20:27:50

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: [Guide] [C#] Using InitParse.cs

Jabatheblob1 wrote:
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.


http://i.imgur.com/bjvgH5L.png?1

Offline

#16 2015-04-04 20:41:18

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: [Guide] [C#] Using InitParse.cs

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

Jabatheblob11428176478491043

Board footer

Powered by FluxBB

[ Started around 1733037668.2543 - Generated in 0.303 seconds, 12 queries executed - Memory usage: 1.71 MiB (Peak: 1.96 MiB) ]