last day (14 days later) » 

3:30 AM
hi
 
Hello Keith!
I'm trying hard to understand what you are doing but I see you have mentioned Interface . How will that help me?
 
so the real problem was how to give child objects access to the container they are in?
 
I'm my situation I don't want every object to get the list passed to them, just the ones that need it
 
do you have different objects in the list?
 
@KeithNicholas Yes, something like that. And Yes I have different objects in the list.
 
3:33 AM
how do you know which object needs it or not?
 
Kind of like this logic:

Class zombie
Update: Finds player coordinates and calculates direction

Class player:
Doesn't need to know anything about the zombies.
And both of them are updated in the main loop.
 
ahhh
just a sec.
 
Okay, thank you for your help.
 
just need to write some example code
class Zombie
{
public void Update(Player player)
{
}
}


class Player
{
public void Update(List<Zombie> zombies)
{
}
}


public class Game
{
List<Zombie> _zombies = new List<Zombie>();
Player _player;

public void Update()
{
_player.Update(_zombies);
_zombies.ForEach(z => z.Update(_player));
}
}
this seperates out the two concepts
 
Ahh, so that's where it comes down too... It's really going to take a lot of work to get use to C#. I've been using game maker for most of my life and it allows for things like: Changing views with any object, checking variables of any instance that's currently active, changing each objects individual depth which sorts out what order an instances code is executed...

Thanks for your help! I'm just gonna have to develop more C# thinking on the way.
 
3:44 AM
you CAN do that kind of stuff
 
It takes a lot more thinking though, doesn't it?
 
kind of, it just makes it a bit messier
 
Well yeah.. I just asked a dumb quesiton.
 
C# is a typed language, meaning you generally want to keep things like players and zombies as seperate concepts
if you mix types together then you have to always first ask what type are you? ok, you are a zombie, so I'm gonna do this
which is more inefficient
 
That is true, but what about a depth system?
 
3:46 AM
as opposed to, ok, all my zombies are here, do this! my player is here, do that!
 
Like you said, I'd need to check the types, but is that not worth it?
I guess that's up to me to decide in the end l:
 
just a sec, I'll do another version...
 
A friend of mine is a big programmer and he always said: Don't become a "hack" programmer. Which he meant try to keep as man IF statements out of your programs as possible.
 
public class Actor
{
int Depth { get; set; }
List<IActor> Actors { get; set;}
}


class Zombie : Actor
{
public void Update()
{
var player = Actors.Where(a => a is Zombie).FirstOrDefault();
}
}


class Player : Actor
{
public void Update()
{
var zombies = Actors.Where(a => a is Zombie).ToList();
}
}


public class Game
{
List<Actor> _actors;

actors.Add(new Zombie());
actors.Add(new Zombie());
actors.Add(new Player());


public void Update()
{
_actors.OrderBy(a => a.Depth).ForEach(a => a.Update);
thats lumping them together
errrr... var player = Actors.Where(a => a is Player).FirstOrDefault();
 
I tried looking up what => was but nothing came up. What does that do?
 
3:56 AM
its called a lambda
 
Okay I'll do some research on that.
 
its like a mini function
this Actors.Where is using "Linq"
so, Actors.Where() will apply a filter, to the collection
a -> a is player is the same as writing a function bool isAPlayer(Actor a) { return a is Player; }
ToList will make it go through the entire list using that filter
FirstOrDefault will go through the list till it gets a match, and returns 1 result
or returns null
 
I'm still trying to comprehend your code! hahaha, This is like nothing I've experienced. I'm so use to scripting languages like javascript and php this is next level stuff to me.

I am understanding as I read through it, and what you're saying above this I'm understanding a little bit too.
 
linq takes a little bit to get used to, but its very powerful
it allows whats called "functional" programming
 
Linq is the .Where right?
 
4:04 AM
yeah, Where ToList FirstOrDefault and many other operators
 
what is work around scopes?
 
This was for a specific question
 
i see
 
Those are all operators of List right? And I am understanding your code a lot more now that I put it into visual studio. Just one thing, what package is "Iactor" found in?
 
its not
I defined IActor
public interface IActor { } creates an interface, meaning any class can say it implements that interface
and then you know any operation on the interface works on any class that says it implements it
in the second example I made an Actor class and then inherited off it
 
4:13 AM
Like this:
public interface IChild
{
void update();
List<IChild> Parent { get; set; }
}

Right?
 
righy
I just called it Actor because zombies and players are like actors in a play / game :)
 
Alright, so when I copied your code it had a lot of errors . I fixed them up, the only one I couldn't figure out was this:
public class Actor
{
int Depth { get; set; }
List<IActor> Actors { get; set;}
}
IActor Doesn't exist.. And I'm not sure how it's supposed to look. I posted your second example, but that confused me
Also, By making it {get; set;} that makes the Actors list empty but adjustable, right?
--- I fixed everything now I got a very weird error. *Error	1	'System.Linq.IOrderedEnumerable<simple_engine_for_game.Actor>' does not contain a definition for 'ForEach' and no extension method 'ForEach' accepting a first argument of type 'System.Linq.IOrderedEnumerable<simple_engine_for_game.Actor>' could be found (are you missing a using directive or an assembly reference?)
 
4:34 AM
Thanks for your help anyways! I wasn't expecting too much of your time and I'm going to be demanding. You gave me enough to work on so I'll educate myself from what you have gave me!
 

last day (14 days later) »