Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamically storing properties depending on position

New Here ,
Mar 28, 2014 Mar 28, 2014

Okay i am creating a tile based game, everytime i move the character i want to store his walking direction for example dirx = 1 , diry = 0. The idea being that when my enemies reach a tile where the character has been it can load the directions and walk the same way. How do i associate the directions with the current tile?

Something like this is my idea but i dont know how to actually program it.

private var giveTileDirections():void

{

          var xdir = this.dirx;

          var ydir = this.diry;

}

Thanks in advance

TOPICS
ActionScript
393
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 28, 2014 Mar 28, 2014

How you write the code depends on what class the code is associated with.  "this" will be identifying the class object, which based on your description will be a tile, so if you want to assign the direction of some other object (the character) then you want to target that character, not "this"

When you declare the function, you use the word "function", not "var"

When you declare the variables you should designate what class they are, and they should be declared outside the function if you intend t

...
Translate
LEGEND ,
Mar 28, 2014 Mar 28, 2014

How you write the code depends on what class the code is associated with.  "this" will be identifying the class object, which based on your description will be a tile, so if you want to assign the direction of some other object (the character) then you want to target that character, not "this"

When you declare the function, you use the word "function", not "var"

When you declare the variables you should designate what class they are, and they should be declared outside the function if you intend that they be available outside of the class.

So the code might look something like this but only you can figure out how you actually want to program it and what you actually intended for each thing you showed....

public var xdir:int;

public var ydir:int;

private function giveTileDirections():void

{

          xdir = character.dirx;

          ydir = character.diry;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 28, 2014 Mar 28, 2014

Wow i was really tired when i wrote this discussion. Thanks for your help i figured it out. How do i remove a discussion like this one?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 28, 2014 Mar 28, 2014
LATEST

The only way you can remove a discussion is to do so before someone answers it.  It won't hurt to keep it in the event someone else learns something from it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines