#archived-code-advanced

1 messages ยท Page 204 of 1

tough knoll
#

So like

#

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)

untold moth
#

Not necessarily. It just makes us harder to understand the issue. Especially, since you don't share the whole thing...

tough knoll
#

But even this is a bizarre way of doing it. There's nothing strictly illegal about it but it's obtuse

untold moth
#

But I guess Dizzie cracked it.

tough knoll
#

See how dlich wasn't even able to parse what you were doing? It's confusing : p

#

This is hardly an advanced code problem

leaden trellis
#

oh

#

I mean I can def share the whole thing but its mostly redundant to the problem besides what I shared

tough knoll
#

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

leaden trellis
#

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

tough knoll
#

It does not

leaden trellis
#

Okay, good to know

tough knoll
#

It's basic C# syntax

#

I recommend doing some C# tutorials

leaden trellis
#

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

tough knoll
#

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;

leaden trellis
#

oh. strange I thought it was a list in list problem. good to know it wasnt

tough knoll
#

The empty parentheses are important, that's what tells the compiler where the type name ends

leaden trellis
#

Okay but also turnOrder is a class and I thought class' could be called from anywhere?

tough knoll
#

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

leaden trellis
#

Did what you said and got this instead

tough knoll
#

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

leaden trellis
tough knoll
#
ATurnOrder.TurnOrder.Add(playerClone);
RoundOrder.Add( ATurnOrder );```
leaden trellis
#

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

thin mesa
#

your turnOrder class has a public field called TurnOrder that is a list you can add to

leaden trellis
#

Yeah, does that break things?

thin mesa
#

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

leaden trellis
thin mesa
#

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

leaden trellis
tough knoll
#

I edited it

#

my bad dude

#

a bug ran across my screen

#

as I was typing

thin mesa
#

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)

tough knoll
#

<_<

leaden trellis
#

Epic, thanks man will test that out

tough knoll
#

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

leaden trellis
#

Definitly, also its for a project I'm doing with friends so learning and also jumping ahead at times

thin mesa
leaden trellis
#

I figured this was an advance question but guess I was wrong.

thin mesa
#

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

leaden trellis
#

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

tough knoll
#

Name your things clearly distinct names

#

and use different capitalization schemes for different things

#

When in doubt just use microsoft default for style guide

thin mesa
distant pivot
#

unit is a scriptableObject, not a gameobject

#

can I link the ScriptableObject and a gameobject ?

heady bane
#

How could I use that to set a body field though?

novel plinth
#

*Im laughing bcos of the typo

heady bane
#

I just saw

#

fixed it

umbral trail
#

Construct a UploadHandlerRaw with the body encoded as utf8 I guess

distant pivot
#

I'm gonna rephrase my question :
How to keep a link between a ScriptableObject, and the instantiated game object that comes from it ?

thin mesa
#

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

distant pivot
#

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)

thin mesa
#

okay so what does that have to do with the question you asked? and how is this an advanced issue?

distant pivot
#

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

thin mesa
#

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)

distant pivot
#

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

fresh salmon
#

You can pass the objects as arguments to your delegate types

#

So in the handlers, you have your links

distant pivot
#

Thanks ๐Ÿ™‚

stuck onyx
#

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

ivory prawn
#

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.

fresh salmon
#

Awaiting will not block the calling thread, as long as the method that contains the await instructions is also awaited at some point

ivory prawn
#

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

stuck onyx
#

ah ok ok ๐Ÿ˜„

ivory prawn
#

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.

stuck onyx
#

yeah thats what i thought, thanks ๐Ÿ‘

ivory prawn
#

Sorry about that, don't know what I was thinking. Haven't had coffee! ๐Ÿ˜–

fresh salmon
#

Basically, async/await generates a whole class that contains a state machine, tracking the progress of the task

ivory prawn
#

I use it all day every day haha

stuck onyx
ivory prawn
#

can you use the profiler?

stuck onyx
#

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

ivory prawn
#

It's definitely worth looking it back up again. It's one of the easier to use and more helpful profilers I've used.

stuck onyx
#

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

ivory prawn
#

Blocking and waiting for an async call is actually really hard and there still isn't really a nice "official" way to do it.

stuck onyx
umbral trail
#

Wouldn't that potentially deadlock?

final steeple
#

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

rugged radish
stuck onyx