How to automatically generate a new int with a specific name?
Hello!
I need to automatically generate an int with a specific name taken from PlayerPrefs. Here's the idea:
//create the int
void CreateInt()
{
new int PlayerPrefs.GetString("WhatToNameTheInt");
}
Obviously that code won't work. I've solved much harder C# issues, but this seemingly simply concept is bugging me...
Thanks for your ideas!
$$anonymous$$y initial thought is: "Why?"
Is the player going to see your code?
No, the player won't see it. But this is the idea: I'm making a base. The base has many slots. On each slot you can mount an upgrade. Here's what I've done: Detect what slot to upgrade Save data with serializer.
What I need to do is select an upgrade for each slot and save it. I'm thinking of generating an int for each slot, and then saving that. Since I have many slots, it won't be easy to do that manually.
Do you have any ideas? Thanks
Wouldn't a simple list of upgrades be easier?
Or, if you wanted to make a "slot" something more complicated than just something an upgrade goes in, you could define a slot class and have a list of slots.
Have a class, planet, that has some information about a planet, and an object of type PlanetaryBase.
Class PlanetaryBase has some information about bases, and an array of slot objects.
Class slot has some information about slots, and an object for an upgrade.
Class upgrade has some information about upgrades, and is extended by other upgrade types that provide specific upgrade functionality.
Then when you save the planet data, it saves the base data, which saves the slot data... etc.
Answer by DroidifyDevs · Jun 24, 2016 at 05:02 AM
@ChrisAngelMindmapfreak I can't reply to you either :/
I've never used C# dictionaries before... I'll give it a shot as this quick example that Bing gave me seems to be close to what I need:
using System;
using System.Collections.Generic;
namespace DictionaryTest {
public class Solution {
static void Main(String[] args) {
Dictionary<string, string> dictionary = new Dictionary<string, string>();
// Add values in different ways
dictionary.Add("Key1", "Value1");
dictionary["Key2"] = "Value2";
int size = dictionary.Count;
string key1Value = dictionary["Key1"];
string key2Value = dictionary["Key2"];
bool containsKey3 = dictionary.ContainsKey("Key3");
Console.WriteLine("Dictionary size: " + size);
Console.WriteLine("Key 1 value: " + key1Value);
Console.WriteLine("Key 2 value: " + key2Value);
Console.WriteLine("Does Key3 exist? " + containsKey3);
}
}
}
Hopefully I'll be able to figure this out on my own, thanks!