#Scriptable Objects - Same Outcome

1 messages · Page 1 of 1 (latest)

sudden mantle
#

Hello, Working with Scriptable Objects for a game I am developing with me and my friend. Using it to store separate events as objects which can be called to display with options with how to deal with it; each giving a outcome like losing 10 gold, etc.

Being the least code literate out of the two of us I coded (aka copied 90% of it) a resource management/display script:
https://paste.mod.gg/iipapofrqbzo/0
and then hooked it up to the buttons to do their respective action

The issue then is that tied to the "Option 1" of every event, no matter which event it loads option 1 will always give the same outcome. I brought up cloning the Scriptable Object instance but my friend said along the lines of "no, that's overkill, imagine making a copy of a script for every event" or along those lines. I am not sure where to go from here, brute forcing it doesn't seem the most optimal thing to do but idk, normally I would turn to her but she is swamped with all the coding and I want to put in my 2 cents and learn to contribute beyond just saying "I want it like this", any other ideas on how I could go about doing this? Thanks.

dire wasp
#

cloning the SO instance is also not at all equivalent to "making a copy of a script"

sudden mantle
dire wasp
#

can you paste code with the same links you used above? its a lot easier to go through

#

just to make it clear, so this first screenshot is a CourtEvents, and you're using that to load the options shown in the initial screenshot of your question.
nothing here seems to do anything when the button is clicked

#

Can you check the first button in your UI, see if anything there is set to happen under the unity event? Or is there other code that handles logic when the button is pressed?

sudden mantle
#

I just have the Resource Management script attached to the button in the inspector for the button related to option 1, we have very few scripts and I kinda just wired them through the inspector

CourtSystem - https://paste.mod.gg/svbbqqkwehdi/0

dire wasp
#

right now you have no logic tied to a CourtEvents. Does button 2 or 3 do anything?

sudden mantle
#

Nothing as of now, they are empty, just been trying to find a work around to this current issue (for buttons 2 and 3)

#

The overall court Ui though is controlled by the Court System script

dire wasp
#

You cant use the unity event in UI here because you dont want hardcoded functionality (I think?)

sudden mantle
#

Well I kinda just need to figure out a system to where this general issue isn't a thing anymore. AddListner might fix this issue from what I see of it and how I could use to listen to what event is currently displayed and have it change the button (?) though I am pretty sure that's not how that works in this context

#

can you even pass arguments through events? because if not then this wouldn't work

dire wasp
#

yes you can pass arguments though im not entirely sure what you need it for here. Maybe describe what should actually happen when you press Button1 2 and 3

sudden mantle
#

Well the buttons are just different options given to the player to react to a given event, kinda like dialogue options in most games, sometimes there are only 2 options to decided between, sometimes more depending on the nature of the event

dire wasp
#

either way the only way here to add functionality when the button is pressed is through AddListener. you need to be able to answer the question above to be able to code this

sudden mantle
#

ah sorry
currently they are just used to edit the resource amount you have (e.g option 1 takes away 10 gold from your stockpile, but gives 50 food lets say)

If the addListener works then will that mean we'll just have to code in a lot of hard-coded functions for each of these outcomes?

dire wasp
# sudden mantle ah sorry currently they are just used to edit the resource amount you have (e.g ...

its not hardcoded if thats the functionality you actually need in the game. You just need to find a way to associate "option 1" with "takes away 10 gold from your stockpile, but gives 50 food". Maybe even declare the possible outcomes in your CourtEvents and use your own unityevent to determine which method to call. No matter what, you need to use the buttons OnClick event first or you wont know when a button has been pressed

#

theres lots of ways to proceed here

sudden mantle
#

I can tell lol, there is a lot of ways I can go about doing this, that was partially why i came here, I needed a fix for the now and to future proof this, I am sure with this system it can handle stuff beyond adjusting the numbers for my resources (e.g transferring resources to another kingdom, or causing an event chain, etc)

dire wasp
#

well the answer to your original issue was addressed above, that its doing the same logic for every CourtEvent because you have a listener assigned in the UI. this doesnt go away ever so it invokes everytime you press the button

#

first try actually just adding functionality through code before you worry about doing it in a modular way