I’m attempting to create a quest system using mostly simple coding techniques. For the hub I’m using arrays to catch all the individual quests as you find them in the world and set them into a “current quests” format. I’ve solved a couple strange ‘index out of range’ problems when suddenly another terrible problem reared it’s ugly head. The quests won’t self identify and instead when I call for the script or the game object it sends a game object or script from every object with the script on it? How would one go about identifying a specific instance of a script in-game among multiple scripts so that you could grab that instance’s unique variables for a quest system? Thanks in advance for any advice.
You can identify it from the .name of the underlying Game Object the script is attached to, as long as that is unique.
Otherwise you could provide a unique ID (usually just an ever-incremented integer) with each newly created quest, and use that to populate something like a Dictionary that points to your quest scripts for rapid lookup.
A better way is to have a Quest Manager that sort of does either of the above steps in a way that all points in your application would use the Quest Manager to make, find, use, and mark as complete all of your quests.
If you only want one system of quests going, you could write your Quest Manager as static methods inside the Quest script itself to give it first-class access to the properties within a quest. I do this often to simplify the plumbing between Quest Manager and Quest type relationships.
I like the singleton idea and I will probably implement that along the way.
My problem is more I don’t know how to identify in-script which instance a specific bool came from, seeing as ideally there will be an indefinitely large number of local quests running in a final product using the system.
Problem Redefined:
It seems the bool, meant to signify success, which is sent from the local quest script to the quest hub script carries no information with it. So every solution I can think of leads to a list of every quest, because the quest hub script registers the bool as coming from every instance. Even the things I’ve thought of as too time consuming to try (instantiating some object onto the local quest object to signify the specific quest) seem like they would lead to the same logical conclusion (an instantiation of the object on every local quest object). Recently I’ve used something similar to identify different versions of same scripts using the center point of a first person view, so it’s basically the same thing, but without an in-game object to “choose” the script.
Basically the script itself needs to be able to realize somehow that it is the current primary script among a huge collection of the same script. I think that last sentence sums it up quite nicely.
I’m having difficulty envisaging what structure you’re using… could you explain what scripts/class/design you are using?
Sure that sounds fun.
The local quest system is a real gem, the hard part is getting a quest hub script that does what I want it to do:
Basically the local quest system runs on an integer, which you make public. You can set it to 3 in the script for now, but you can change it in the inspector for longer quests. You set another int and you set it to increment with a bool (which is a bit of a pain, I’m sure there’s easier ways than how I did it, but it’s all about knowing the tools, right?). After that, you just write a series of “if, then” statements for the beginning, middle, and end of your quests, or whatever you want (the end of your quest being your public int).
the quest hub definitely has taken alot more finagling, but it’s a fun way to play with quests without having to write my own Inspector:
Basically it consists of an array of local quest scripts, an int to hold the number of quests there are, and an int to signify that the number of quests have changed (by replicating the quest number in the start method). So in my if/then’s for the local quests, it says, “if the increment = 1, add quest”. That, through checking the relationship between the two int’s in the quest hub, causes the array to increment by 1.
the cool thing about using an array of the scripts is if it works then you can have access to any number of variables. Such as strings for names and descriptions, certain restrictions on quest starts or specific rewards for completing quests etc.
If you have any questions let me know.
Solved the problem with a new local integer and a for each loop.
ttyl.