Rewriting Cellular Automata C# to JS
Hey all. If you've gotten this far, thanks for reading. I'm a new programmer and I already know a little bit of JavaScript so I intend to use that as my development language for now. I'm trying to work my way through Sebastian Lague's procedural generation tutorial and I'm having to rewrite the code as I go. I was doing fine until I ran into assigning values to the spaces in the matrices for the initial map roll. Here's my code:
var height: int;
var width: int;
var fill: float;
function mapGen(width, height) {
var map = [width, height];
mapFill(width, height);
};
function mapFill(width, height) {
for (var x = 0; x <= width; x ++) {
for (var y = 0; y <= height; y ++) {
if (x == 0 || x == width - 1 || y == 0 || y == height - 1) {
map[x,y] = 1;
};
else {
map[x,y] = (Math.random() < fill);
};
};
};
};
Unity keeps throwing errors at the map[x,y] lines. The error is BCE0048: Type "function(object, function): System.Collections.IEnumerable" does not support slicing. This is really irksome to me because the function it seems to be complaining about is apparently invisible. The syntax it gives me does not point me to any errors elsewhere in my code.
I haven't worked it out past those errors. If you see anything else, feel free to point it out, but I don't think I'll have issues with anything else.
Answer by CascadiaLeijona · Sep 04, 2015 at 03:39 PM
It looks like my error was in the matrix generator code. I wrote out a nested array function and it seems to be working fine now.
var matrix = [];
for (x = 0; x < w; x++) {
matrix[x] = new Array(h);
};
Might need to fine-tune this but it got rid of the errors, so I'm happy.
I'm having quite a bit of trouble converting this as well. If you could show me some finished code that does the same thing that would be a great help. I'm trying to create an algorithm that combines Cellular Automata and BSP Tree, but I can't really get anywhere if I don't know how to write the code for Cellular Automata. Any help would be greatly appreciated.
Your answer
Follow this Question
Related Questions
Find border of Matrix (east, west, north, south) 0 Answers
I cant figure out why my array is causing the error 'System.Type' does not support slicing. 0 Answers
How do I optimize transforming vertices to screen space? 1 Answer
3d grid/matrix inside a mesh 1 Answer
Rotate gameObject by applying rotation matrix in unity3d 0 Answers