#Sycarium's slight issue of absolute madness. easier solutions would be helpful.

1 messages · Page 1 of 1 (latest)

magic plume
#

So like... I have 7 scripts at the very least working in tandem to get a SIMPLE result, Toggle between panels 1&2. Then, toggle within 4 panels inside the second panel. each which has 5 topics (non instantiated) and a Panel with 4 tasks in it. (tasks are instantiated from prefab) (rn only first 4 tasks are instantiated. making one panel prefab (first panel). THEN that panel prefab will be instantiated into 20 panels, each corresponding to their topic. (20 topics. 20 panels. 80 tasks.) Now, that would be all simple enough on its own, right? But here is where the fun begins. Each Panel operates with a button... Trough 2 scripts. a button manager + a ButtonBehaviour script. (except the first 2, which toggle trough much simpler things). Making 5 scripts for panels. (the dual scripts are replicated with slight name differences and a different private/public get set) (making it into one script proved extremely difficult bordering on the impossible).

And now. The first toggle fcks up the other toggles, which either work, or dont work depending which panels get opened or closed at which times, and may open the wrong panels at the wrong time, or which variant of the script I use. (they all have their own problems). I assume, that the second toggle fcks up the entirety of the third toggle the same way. There are no errors shown in vs studio. there are no errors shown on unity console. :) (well, the latest version has 1 error on the console which didn't on the IDENTICAL previous script. But since the previous didnt work either, its not the root) :)

edit. Also of note so you dont waste energy today, if you arent into deep thoughts for little gain... since I'll have to leave this here for now without my presence. If you have ideas on how to make things work ect. do tell. Ping me if you are interested in figuring it out with me, and you know, I'll try to send you a message when I'm back to work. if you only want to help with direct contact that's gonna be tomorrow then.

#

^the basic 2 script button manager + button behaviour. they work well on their own.

#

https://hastepaste.com/view/5PmhP0X instantiating script. using the above scripts, it works better than with the latter script. despite being virtually the same. (but, you needed to assign the button behavior script TWICE in the inspector for it to work...)

#

the topic button behaviour is a replicant of the tab button behaviour above.^

#

and uh. yeah. every bit of information will eventually come from scriptable objects. so yay for that can of worms!

#

(if tab) (this.close()) on line 35 of tab button behaviour was an issue fix after I applied it to the second buttons with different needs. It wasnt needed before that, and might now be redundant. (the issues remain... but with no reason to exist anymore).

#

but yeah. everything's assigned pretty much right. as far as I can tell. and oh, the topic task panels started spawning to wrong locations after switching from tabbuttonbehaviour to topicbuttonbehaviour.

#

this is what it looks like.

#

and uh. I'll just copy all that if this gets deleted due to misconduct on not being present. but like.. I cant exactly be present. and I dont expect anyone sane to answer to it within a reasonable amount of time. :P

#

Nonpresent (sry) Sycarium's slight issue of absolute madness. easier solutions would be helpful.

#

Nonpresent Sycarium's slight issue of absolute madness. easier solutions would be helpful.

magic plume
#

Sycarium's slight issue of absolute madness. easier solutions would be helpful.

elder pond
#

I'm not going through all that. Which script is InstantiatePrefab

elder pond
magic plume
#

that's I think not really the main issue here.

elder pond
#

Then what's the error you're trying to fix

magic plume
#

another version of the script had no errors, but didnt work

#

its more of an idea thing.

#

a couple of scripts dont work together. cancel each other out.

#

panel toggle A and B basically.

elder pond
#

So what doesn't work

magic plume
#

and therefore, also B and C.

elder pond
#

Which part of what script doesn't work

magic plume
#

toggle script A toggles between main panel A and B. toggle script B toggles between side panels inside B panel 1-4. both work. but if used in unison, say, you go to B, open tab 2. close the entire panel. open it again, and now tab 2 is probably unclickable.

elder pond
magic plume
#

its probably improperly closed in the first script.

elder pond
#

Show where you make the tabs do stuff?

magic plume
#

the scripts?

elder pond
#

Wherever. I don't know how you're assigning behaviour to the tabs

#

Are the tabs UI Toggles?

magic plume
#

they are button behaviours.

elder pond
#

So show me where you add and remove the listeners of the buttons

magic plume
magic plume
elder pond
#

Maybe. How about changing that to Awake and OnDestroy instead

#

Then it won't be affected by things being enabled and disabled

magic plume
#

I can try that, but ofc it sorta breaks the code rn.

#

yeah unsure what to do here. tabButtonBehaviour doesnt contain "onPressed" after that.

#

also thinking the onDestroy would be not good, since, you know. the code works on setactives not destroys...

#

and destroys start to eat the processing...

#

then again, maybe the destruction and recreation of a single panel aint that bad.

#

a panel, that contains 100-200 objects in it.

#

thinking, if its addlistener issue, adding/removing on the other script could do it.

elder pond
#

Why do you need to remove and add the listener everytime you open and close it?

magic plume
#

Idno.

elder pond
#

Then don't?

magic plume
#

its not my code originally.

elder pond
#

You can still setactive to show and hide, but the listeners, let the adding and removing be done on creation and destruction

magic plume
#

I think it might be good practice to remove listeners? ive seen it done.

haughty spade
#

Don't the listeners deactivate when you deactivate the script?

elder pond
#

Ugh

magic plume
elder pond
#

I don't know what you mean

#

Or why you're so confused

magic plume
elder pond
#

I'm not saying don't remove listeners, I'm saying you don't need to add and remove them everytime you hide or show them

#

Instead, you add them when they're created, which is only going to be once in their lifetime

magic plume
#

^sounds reasonable + saves computing Id imagine.

elder pond
#

And remove them when you destroy them, which is when you exit the scene or the application

haughty spade
#

All I would recommend is merging the scripts if they cancel

magic plume
elder pond
#

Would not recommended making scripts you don't understand even larger and more complicated by merging

haughty spade
#

Then make a static toggle

magic plume
#

it's the logical approach. I think I'd have gone for it on my own eventually.^

#

a static toggle...?

haughty spade
#

Bool or Int

magic plume
#

before dwelling on these. so this makes onPressed obsolete. And, if onPressed was removed. "this" as well.

#

I dont really get why the latter happens. "this" should exist.

#

cannot convert to unity action

#

^a problem fixed in another place. I can possibly copypaste the solution from there, but I dont even think there should be an issue here.

magic plume
#

you are still going to toggle the bool true /false on click after all.

haughty spade
#

A toggle for the script

magic plume
#

^or, thats how its been done in all google examples.

magic plume
#

or like, just make it a toggle.

haughty spade
#

Also re writing the button may be needed

magic plume
#

yeah...

haughty spade
#

But I dont think thats the solution

haughty spade
magic plume
#

its a good question.

haughty spade
#

Because cant you just straight link the buttons to run functions?

magic plume
#

mm... what do you mean, link?

#

arent they linked trough using the same code rn?

haughty spade
#

So you make a public void function

magic plume
#

okay? I can surely make a new public void function. but what would it do? the script already has a lot of methods/functions, which do the job (beyond the other scripts influence)

#

wouldnt whatever code I'd use still work trough "onPressed"?

#

or onclick or whatever.

haughty spade
#

Then on the button there is an on click function

magic plume
#

ah, I see.

#

and that would work onAwake

haughty spade
#

It would work at any time its a separate event running a custom function

#

It should be this simple

#

Do the buttons currently do anything other than debug log?

#

Sorry its just alot of script

magic plume
#

there, it works.

magic plume
haughty spade
#

I fixed it you have to drag the gameobject

#

You can effectively call your "On Pressed" Functions using this method and it will work independently of awake and other buttons that are linked to different functions

magic plume
#

oh really? !

#

no need to alter things further would be great.

haughty spade
magic plume
#

hm. I can try that. but I think it didnt originally need that, it worked without it.

#

just not in tandem. weird...

haughty spade
#

Yes because perhaps its running the same listener overlapping

#

And using the built in button On Click function activator, it would simplify it quite a bit.

#

And you can link it to do various other things by controlling gameobjects and running several on click functions at once

magic plume
#

hmm. okay

#

so uh. normally, the functions appear here. but in this case, not so much.

haughty spade
#

The only limitation is you cannot send variables straight from the button but that can be worked around by sending/looking for public variables through script instead

#

Do you use static variables?

magic plume
#

I think they are merely public.

#

or serialized field something.

haughty spade
#

Then you can click the script and then the functions in the script by pressing 'No Function'

magic plume
#

ah right. its been so long since I last did that...

#

I think I switched from this kinda approach at having made the GameManager.

#

and then it just devolved into scripts->on the objects they work on.

haughty spade
# magic plume I think they are merely public.

Statics are useful

// Set the variable
public class Number : MonoBehaviour {
  public static int myNumber = 5;
}


// From another script
public class GameScript : MonoBehaviour {
Debug.Log(Number.myNumber);
}



#

You just write the name of the class then . and then the name of the variable

magic plume
#

yeah. there has to be a downside to it though.

#

people keep using mostly publics/serialized fields.

magic plume
haughty spade
#

And statics are effective when you have multiple enemies with the same script because then the number is the same for all the enemies

magic plume
#

ah yes. this is where the variable not existing comes into play. no target for the script. wont know which panel to open?

#

and if I have the script in these objects that would define the targets, itd run the script twice...

haughty spade
#

I don't think statics are too heavy such as FindObjectOfType or something as statics just get the already serialized classes and allows the variables to be accessed by other classes

magic plume
haughty spade
#

a separate function for each button is alot simpler than all of that complicated listener shenanigans

magic plume
haughty spade
#

You can put many voids on a single script

magic plume
#

a bit like how youd rather forloop

magic plume
haughty spade
#

You don't have that many buttons do you?

magic plume
#

yeah, thats an approach I could see working out/usign.

magic plume
#

...yeah. I do.

haughty spade
#

What do you need so many buttons for

magic plume
#

this is the beginning. if I get this working, then I need to apply it to ... 20 other buttons ,each which open a panel, which then need to work in synch with the 2 other scripts.

#

but it seems less impossible now, if this works.

haughty spade
#

Damn

magic plume
#

making things 5x more difficult for me

#

all for the slightest increase in efficiency.

#

*keep mixing the words... all too easy.

haughty spade
#

I made a game with like 10 buttons that have changing text on them and it took some time to link them all up to their functions but it wasn't nearly this hard

magic plume
#

working with /assigning non existent objects is tight

magic plume
#

it gets even more funky after I need to begin altering all of those things trough scriptable objects + their managers.

haughty spade
#

If you want to use the OnListener approach still I would suggest isolating the part that needs to be rewritten to make it easer for a solution to be found

#

Because you have alot of scripts which I usually don't like doing but thats just me

magic plume
#

whats the OnListener approach?

#

it's 9 scripts to do a single job/work together and counting.

haughty spade
#

Listener OnClick/Press or something... what you were trying to do

magic plume
#

I think this is pretty similar to that.

haughty spade
#

I usually put it all in one script so its easy to manage the different functions in relation to each other

#

If its too messy you can always add some space to visually seperate the sections as C# is quite lenient for its formatting

#

Sorry for not being too helpful

magic plume
# haughty spade Then make more functions

normally youd assign trough the inspector. in this case, I'd have to assign trough the script. find() comes to mind, but then, I could get the object names inside a SO list of some kind. what would you do here?

haughty spade
#

I'm best at making 3D fps games I don't really focus on 2D or UI too deeply

magic plume
magic plume
magic plume
#

but I like it.

haughty spade
#

I mean space in the 1 big script

magic plume
#

yah.

magic plume
#

you know what I was going to do?

#

I was going to alter every single script

#

to work in union. to throw their variables, their setactives into the other ones. link 9 scripts to use each others functions in a web like manner.

#

aint nobody able to read trough that no matter what commits/documentations Id add.

#

ah yes. now I remember an issue here... ^^' why I resorted to 2 more scripts... the Tab is a private set. (in the TabButtonBehaviour)

#

and turning it into public set.

#

fcks up the code

#

well, only in the sense that... I cant use the same script for the instantiated panels & their activating buttons.

magic plume
#

:( theres a lot of difficulties with this...

magic plume
#

maybe alternative route would be better? fixing this ^

#

to match the other script better.

magic plume
#

gah. I think I got it to working. The TabButtonBehaviour is now activated trough onClick... But the problem still remains...