Hey Guys
Im back with more noob questions. Could someone please explain to me this Error, from what Ive found on the internet Im setting and getting at the same time and should create a temp var. Im not really clear how or why. Please help me
Thank heaps , hopefully I can contribute back at some point lol
Assets/Scripts/GridScripts/GridDistribution.cs(97,56): error CS1612: Cannot modify a value type return value of `NodeDistribution.nodeAttrDistribution’. Consider storing the value in a temporary variable
Assets/Scripts/GridScripts/GridDistribution.cs(102,57): error CS1612: Cannot modify a value type return value of `NodeDistribution.nodeAttrDistribution’. Consider storing the value in a temporary variable
Assets/Scripts/GridScripts/GridDistribution.cs(104,57): error CS1612: Cannot modify a value type return value of `NodeDistribution.nodeAttrDistribution’. Consider storing the value in a temporary variable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridDistribution : GridBase, IGridDistCellAuto<GridDistribution> {
public NodeDistribution nodeDistribution;
public NodeDistribution[,] gridNodeDistribution;
public int width;
public int Width
{
get
{
return gridSizeX;
}
}
public int height;
public int Height
{
get
{
return gridSizeY;
}
}
public string seed;
public string Seed
{
get
{
return seed;
}
set
{
seed = value;
}
}
public bool useRandomSeed;
public bool UseRandomSeed
{
get
{
return useRandomSeed;
}
set
{
useRandomSeed = value;
}
}
public bool invert;
public bool Invert
{
get
{
return invert;
}
set
{
invert = value;
}
}
[Range(0,100)]
public int randomFillPercent;
public int RandomFillPercent
{
get
{
return randomFillPercent;
}
set
{
randomFillPercent = value;
}
}
// Use this for initialization
void Start () {
// Create a grid
gridNodeDistribution = CreateGridT<NodeDistribution> (nodeDistribution, gridNodeDistribution);
}
// Inferance methods
public void RandomFillMapT<T>( T[,] gridIn ) where T : GridDistribution{
if (useRandomSeed) {
seed = Time.time.ToString();
}
System.Random pseudoRandom = new System.Random(seed.GetHashCode());
for (int x = 0; x < width; x ++) {
for (int y = 0; y < height; y ++) {
if (x == 0 || x == width-1 || y == 0 || y == height -1) {
gridIn[x,y].nodeDistribution.nodeAttrDistribution.filled = 1;
}
else {
if (invert)
gridIn[x,y].nodeDistribution.nodeAttrDistribution.filled = (pseudoRandom.Next (0, 100) < randomFillPercent) ? 0 : 1;
else {
gridIn[x,y].nodeDistribution.nodeAttrDistribution.filled = (pseudoRandom.Next (0, 100) < randomFillPercent) ? 1 : 0;
}
}
}
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public interface IGridDistCellAuto<T> {
int Width{get;}
int Height{get;}
string Seed{get; set;}
bool UseRandomSeed{get; set;}
bool Invert{get; set;}
int RandomFillPercent{get; set;}
// Randomly fill our grid
void RandomFillMapT<T>( T[,] gridIn ) where T : GridDistribution;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public struct NodeAttrDistribution {
public int filled;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class NodeDistribution : NodeBase {
private NodeAttrDistribution _nodeAttrDistribution;
public NodeAttrDistribution nodeAttrDistribution {
get
{
return _nodeAttrDistribution;
}
set
{
_nodeAttrDistribution = value;
}
}
//
// Constructor running base class constuctor
public NodeDistribution(Vector3 worldPosition, int gridX, int gridY)
: base( worldPosition, gridX, gridY) {
}
}