#archived-code-advanced
1 messages ยท Page 204 of 1
new turnOrder.TurnOrder.add(playerClone)
You're declaring a new object of type turnOrder, but not calling a constructor. Instead you're immediately attempting to access it's list member. This will not work.
You must do new turnOrder().TurnOrder.add(playerClone)
Not necessarily. It just makes us harder to understand the issue. Especially, since you don't share the whole thing...
But even this is a bizarre way of doing it. There's nothing strictly illegal about it but it's obtuse
But I guess Dizzie cracked it.
See how dlich wasn't even able to parse what you were doing? It's confusing : p
This is hardly an advanced code problem
oh
I mean I can def share the whole thing but its mostly redundant to the problem besides what I shared
Just change RoundOrder.Add(new turnOrder.TurnOrder.add(playerClone)); to RoundOrder.Add(new turnOrder().TurnOrder.add(playerClone));
If you don't add the parentheses to call the constructor, it will instead look for a type called turnOrder.TurnOrder.add
ahh thank you. I'll try that and get back to you on it.
also just incase this matters turnOrder is a class inside the main script that is serializable
It does not
Okay, good to know
I've dne a few already but list inside list wasn't taught and is harder than in Python for me at least I guess lol
will do
Your problem isn't related to lists, I'll explain it again:
To create an object in C# is like this
turnOrder YourObject = new turnOrder();
You are doing this: turnOrder YourObject = new turnOrder;
oh. strange I thought it was a list in list problem. good to know it wasnt
The empty parentheses are important, that's what tells the compiler where the type name ends
Okay but also turnOrder is a class and I thought class' could be called from anywhere?
You must have the parentheses after the type name
If you don't, you're telling it to go look for another type within the type
Did what you said and got this instead
ahh
Oh yeah
I'm dumb
sorry, that's just illegal period
Because you're calling a function on the returned type
So now you're returning void out of the Add function
You have to declare it first, then add it to the list
so like this
all good I too am dumb most days while coding
ATurnOrder.TurnOrder.Add(playerClone);
RoundOrder.Add( ATurnOrder );```
Thank you for the code. Just one small thing. I cant call Add on ATurnOrder and i think thats because it's not a list.
I'm going to change
turnOrder ATurnOrder = new turnOrder()
to
turnOrder ATurnOrder = new list<turnOrder>();
that didnt work either
your turnOrder class has a public field called TurnOrder that is a list you can add to
Yeah, does that break things?
no, you just need to add to that since turnOrder is not itself a list. and also this was really not the right channel for your question
I'm trying to just every time I try it then goes and says RoundOrder is incorrect because it needs TurnOrder
RoundOrder is a list of turnOrder. turnOrder contains a list of gameobject. you can add turnOrder objects to RoundOrder and you can add GameObjects to the list in turnOrder
How would I go about doing that? I cant find a good way to do it that doesn't give me any errors like the ones above and is still indexable inside the main list, say I wanted to do RoundOrder[2][3] like in python
so you have this object ATurnOrder that is of type turnOrder. that object contains a list called TurnOrder of type GameObject. you can add a gameobject to that list with ATurnOrder.TurnOrder.Add(gameobject)
<_<
Epic, thanks man will test that out
But yeah like
This is beyond your ability right now IMO
you need to do some learnins
And this is a lesson in why you shouldn't mix type and field names
it's just confusing for everybody
Definitly, also its for a project I'm doing with friends so learning and also jumping ahead at times
for future reference, you should ask these kinds of questions in #๐ปโcode-beginner
I figured this was an advance question but guess I was wrong.
nope, there's nothing special about what you are doing. you have a list of a class that itself contains a list. you were just confusing yourself with how you've named things and somehow thinking that the class was also a list i guess
It's nested classes and nested list but thats beginner stuff lol My abd and also guess I'll move over there since it still gives me another stupid error
Name your things clearly distinct names
and use different capitalization schemes for different things
When in doubt just use microsoft default for style guide
it's explicitly not a nested list. is a list of a class. that class just happens to have a list member that you were trying to access. nested lists would be more list List<List<GameObject>>
Ahh, Good to know that.
unit is a scriptableObject, not a gameobject
can I link the ScriptableObject and a gameobject ?
How could I use that to set a body field though?
*Im laughing bcos of the typo
Construct a UploadHandlerRaw with the body encoded as utf8 I guess
I'm gonna rephrase my question :
How to keep a link between a ScriptableObject, and the instantiated game object that comes from it ?
what do you mean by "keep a link"
what it sounds like you want is just to a reference from one of the two objects to the other
I have a Unit ScriptableObject (that contains, name, speed, etc.) and I'm instantiating Units as gameObject.
Then, I want that new created reference to add it to a UI element (a button, when I click the button, the camera focus on that unit)
okay so what does that have to do with the question you asked? and how is this an advanced issue?
It's all the same question, I'm trying to get a knowledge on how to do things right, I thought observer patter + scriptable objects where more than beginner question
well you still haven't explained what you mean by "keep a link" between the objects (like i said before it sounds like you just want a reference which absolutely would be a beginner question)
I have an EventManager (that keep the delegate and the event)
I have two Observers for now
- One that handles the creation of the gameObject itself
- One that handles the creation of the UI Object
yeah i'm trying to set the reference of the gameObject in the UI Object, but they are created inside the delegate, and I don't know in which order
So, how to get my gameObject reference into the UI Object
But it seems i'm annoying you with this question so let it be, i'll try to find the right solution
You can pass the objects as arguments to your delegate types
So in the handlers, you have your links
Thanks ๐
myStream.WriteAsync is returns a task and im doing
await stream.WriteAsync(......);
this does NOT block the main thread right?
theoretically shouldnt but something's lagging in my script and im not sure of anything anymore
Yes, await will block the thread.
do something like var myTask = stream.WriteAsync(...) and then execution will continue. You can then check myTask.IsCompleted on each Update, or if you get to the point where you have to wait for it to finish before you can continue, then at that point you can await myTask.
Awaiting will not block the calling thread, as long as the method that contains the await instructions is also awaited at some point
Sorry yeah await will block the context that it's running in, but of course that might not be the main thread already.
Argh
Nope
Forget what I said
ah ok ok ๐
Listen to SPR2
No, it won't block. Like, at all. It will return from the function at that point, and then when the task completes, the code after the await will run.
yeah thats what i thought, thanks ๐
Sorry about that, don't know what I was thinking. Haven't had coffee! ๐
Basically, async/await generates a whole class that contains a state machine, tracking the progress of the task
I use it all day every day haha
me doubting of this after so many time is also embarrassing but after so many tests i dont know what the heck is blocking the main thread anymore
can you use the profiler?
i forgot how to use it and i was lazy to learn again, im more familiar with the memory profiler but if this continues ill have to, now i've set StopWatches in every call to see wth is happening
It's definitely worth looking it back up again. It's one of the easier to use and more helpful profilers I've used.
for sure i will have to. i was just too busy with other stuff but i will have to use it again to profile this and more things
Blocking and waiting for an async call is actually really hard and there still isn't really a nice "official" way to do it.
i dont understand, i'm using unitask, might not be the official way but it's a pretty.... good way to do it
Wouldn't that potentially deadlock?
Yes
If the continuation is scheduled to run on the main thread, and you block the main thread waiting for that continuation, then the continuation will never run and you'll deadlock
SynchronizationContext supports hooking into waits, which allows you to process queued operations during that scenario to avoid the deadlock, but I discovered recently that Mono actually has a bug that makes that not work properly for Task.Wait
afaik, it won't block the main thread if that method is actually asynchronous
if it runs something heavy without using multithreading or yielding after reaching a certain threshold, it will lock the main thread
correct, thats how i thought it was , thanks ๐