Skip to main content

News

Topic: Question about API and Obstructions (Read 4080 times) previous topic - next topic

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Question about API and Obstructions
Reply #15
I dunno... I'll need more info such as how you get the (0, 0). It doesn't help me when you post working code! :P
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Question about API and Obstructions
Reply #16
Lol, that's the weird thing. It should work, but doesn't.

I'm guessing the values come from the global variables LastTile and NowTile, but even if I change the values from 0 nothing happens.
I'm also thinking Sphere automatically assigns the placement value (0,0) until input is given, which is part of the reason why it's returning negative tile numbers.

Attached the script to browse through.
Ask questions if something seems confusing,
I will clear things up as quickly and much I'm able to.

Conflict occurs between Lines:
*153-156  (Key_up, check Now Tile)
*168         (Key_down, check Now Tile)
* 13-17    (last and now Tile, global variables)

. . .

[Edit:] Just attempted to wrap the part I think that's the source of conflict "NowTileY/16-7" in Math.abs(); to get an absolute value. however it's still returning a negative number.
Although, it's now a -1 instead of a -6. Always look on the bright side of life I guess.
  • Last Edit: July 09, 2013, 11:13:07 pm by Vakinox

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Question about API and Obstructions
Reply #17

Lol, that's the weird thing. It should work, but doesn't.


No it works I can see that it's not thinking on it's own. I ask, where are you getting the (0, 0) from?

All you need to do is use GetPersonX("name"), and GetPersonY("name"). If you want to get the pixel coords. There's a distinction between pixel and tile coords.

Realtime X/Y coords in tiles:
Code: (javascript) [Select]

var name = GetInputPerson();
var x = Math.floor(GetPersonX(name) / 16);
var y = Math.floor(GetPersonY(name) / 16);

var position = "(" + x + ", " + y + ")";


That's how you get the coordinates of the player. You shouldn't have the Txy(17, 8) = (0, 0) problem by calculating where the player is at when you draw the location string.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Question about API and Obstructions
Reply #18
[Update:] Removed all NowTile variables from conflicting lines in the movement script,
and replaced it with GetPersonX(GetInputPerson())/16, GetPersonY(GetInputPerson())/16 according to the script.

So it removed the error, which turned out to be a fault with I'm guessing using NowTile as a global variable,
which retains the placement values (0,0) at startup and using that in the math.
(note: odd it still didn't change from 0,0 when I changed the values in the globals)

Though, now I'm back to square one with getting stuck inside the obstructing tile.
Think the problem has now been simplified to a mistake in calculations somewhere.


  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Question about API and Obstructions
Reply #19
Movement:
Code: [Select]

function Movement()
{
var Player = GetInputPerson();
if (!IsCommandQueueEmpty(Player)) return;

var x = Math.floor(GetPersonX(Player) / 16);
var y = Math.floor(GetPersonY(Player) / 16);
if (x < 0 || y < 0) return;

TileName = GetTileName(GetTile(x, y, 0));
NextTileName = GetTileName(GetTileInFront());
var Command = null;

//Start defining keys here
if (IsKeyPressed(KEY_UP)   ) { Command = North; QueuePersonCommand(Player, FaceNorth, true); }
if (IsKeyPressed(KEY_DOWN) ) { Command = South; QueuePersonCommand(Player, FaceSouth, true); }
if (IsKeyPressed(KEY_RIGHT)) { Command = East ; QueuePersonCommand(Player, FaceEast, true) ; }
if (IsKeyPressed(KEY_LEFT) ) { Command = West ; QueuePersonCommand(Player, FaceWest, true) ; }

IgnoreTileObstructions(Player, false);

if (NextTileName == "obstruct_n" || NextTileName == "obstruct_nw" || NextTileName == "obstruct_ne" ||
TileName == "obstruct_n" || TileName == "obstruct_nw" || TileName == "obstruct_ne") {
IgnoreTileObstructions(Player, true);
}

if (Command == North && (TileName == "obstruct_n" || TileName == "obstruct_nw" || TileName == "obstruct_ne")) {
Command = null;
}

if (Command != null && !IsObstructed(Player, Command)) {
for (var i = 0; i < 16; ++i) { QueuePersonCommand(Player, Command, false); }
}
}
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Question about API and Obstructions
Reply #20
That is a godsend my friend.
Thank you, bro. Appreciate it.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Question about API and Obstructions
Reply #21
It actually too me quite a bit of time to try and debug that. :P Anyways I think it does what you wanted it to do.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Question about API and Obstructions
Reply #22
It's closer than I was ever going to be.

Still got a few kinks to work out that I can handle, but it's definitely does exactly what I needed it to.