Skip to main content

News

Topic: GetPersonDirection?? (Read 6229 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
GetPersonDirection??
I'm trying to get my bombs functioning properly. The function is bound to key B for Bombs (for now). The function is not updating the person direction. No matter which direction the player is facing it returns the value of North. Any ideas why this might be?
  • Last Edit: August 15, 2017, 11:31:48 pm by Miscreant
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: GetPersonDirection??
Reply #1
The problem lies here:

Code: [Select]
if (PerDir = "North"){
BombX = PerX;
BombY = (PerY - 40);
}else if (PerDir = "South"){
BombX = PerX;
BombY = (PerY + 40);
}else if (PerDir = "East"){
BombX = (PerX + 40);
BombY = PerY;
}else if (PerDir = "West"){
BombX = (PerX - 40);
BombY = PerY;
}

You are using a single = which means assignment, so basically you're setting PerDir to "North" right away in that very first if statement and it skips everything else. You'll want to use == here, which means comparison.

Another thing: person directions are case sensitive, so you'll need to change the capitalization to "north", "south", "east" and "west", unless you also capitalized the directions in the spriteset file (though this will likely break some default functionality in the map engine).

Example:
Code: [Select]
if (PerDir == "north")

Re: GetPersonDirection??
Reply #2
Example:
Code: [Select]
if (PerDir == "north")

My original line was if (PerDir=="North") etc and it kept returning an invalid integer.

Quote
Another thing: person directions are case sensitive, so you'll need to change the capitalization to "north", "south", "east" and "west", unless you also capitalized the directions in the spriteset file (though this will likely break some default functionality in the map engine).

My spritesets are capitalized. It's the natural flow of language and does not seem right if everything is lowercase. However, I went into the spriteset file and changed all the directionals to lowercase and the bombs are now functioning. The directions update and is no longer returning an invalid integer.

I suppose this means that I will have to go and change all the directionals in all my spritesets to lowercase...
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: GetPersonDirection??
Reply #3
The map engine is hardcoded to use default direction names in several places, e.g. here:
https://github.com/fatcerberus/minisphere/blob/v4.8.1/src/minisphere/map_engine.c#L1983-L2006

Programming languages are almost always case-sensitive, with a few exceptions (usually BASIC-derived languages are not case-aware).  And in JS, camelCase is the usual convention, so that's what was chosen for the default direction names.

Whether or not it was wise from a design standpoint to special-case the directional poses at all is a question to ask when the new map engine is being designed. ;)

edit: Your "invalid integer" when using == is probably because GetPersonDirection() returned something other than what your if/elseif tower is checking for, so `BombX` and `BombY` were left undefined.  If you then pass them a function expecting a number, you get an error.  JavaScript doesn't have types like e.g. C++, so that kind of thing isn't checked for you.
  • Last Edit: August 15, 2017, 03:29:24 pm by Fat Cerberus
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: GetPersonDirection??
Reply #4
So, interesting thing: Sphere 1.x does a case-insensitive search when looking for spriteset poses:
https://github.com/sphere-group/sphere/blob/master/sphere/source/common/Spriteset.cpp#L925

miniSphere turns out to do the same:
https://github.com/fatcerberus/minisphere/blob/v4.8.1/src/minisphere/spriteset.c#L642
(strcasecmp() is actually case-insensitive, contrary to what the name suggests)

So I'm actually not sure why capitalizing the direction names in the spriteset doesn't work properly... :-\
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Rhuan
  • [*][*][*][*]
Re: GetPersonDirection??
Reply #5
I suppose this means that I will have to go and change all the directionals in all my spritesets to lowercase...
You can write a script to do that.

Code: [Select]
function convertSprites()
{
  var to_convert = GetFileList("spritesets");
  var temp;

  for(var i = 0, j = 0; i < to_convert.length; ++i)
  {
    if(to_convert[i].slice(to_convert[i].length-5,4)==".rss")
    {
      temp = LoadSpriteset(to_convert[i]);
      for (j = 0; j < temp.directions; ++j)
      {
        temp.directions[j].name =  temp.directions[j].name.toLowerCase();
      }
      temp.save("../other/" + to_convert[i]);
    }
  }
}

Notes:
1. the converted spritesets will be saved in the folder "other" inside your game's folder the originals won't be overwritten.
2. I haven't tested the above but it should work...

Re: GetPersonDirection??
Reply #6
Notes:
1. the converted spritesets will be saved in the folder "other" inside your game's folder the originals won't be overwritten.
2. I haven't tested the above but it should work...

I created an empty project, copied my spritesets into the spriteset folder and executed your code to test it. It did nothing.
Tried it in both Sphere 1.5 & miniSphere.

I don't have that many spritesets to convert. I'll just go through them and edit them by hand.
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

Re: GetPersonDirection??
Reply #7
on a side note, I'm trying to convert the x/y values to something less absolute. I now have a var Bombs=LoadSpriteset("bomb.rss");

I was trying to change the BombX/BombY to something along the lines of (as an example) BombX = PerX + Bombs.width;

Is spriteset_object.width a valid call?
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: GetPersonDirection??
Reply #8
No, but spriteset_obj.images[0].width is.  All images in a spriteset are the same size so you just have to know the size of one of them.
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Rhuan
  • [*][*][*][*]
Re: GetPersonDirection??
Reply #9
Notes:
1. the converted spritesets will be saved in the folder "other" inside your game's folder the originals won't be overwritten.
2. I haven't tested the above but it should work...

I created an empty project, copied my spritesets into the spriteset folder and executed your code to test it. It did nothing.
Tried it in both Sphere 1.5 & miniSphere.

I don't have that many spritesets to convert. I'll just go through them and edit them by hand.
DId you call the function? I've written a function to do the conversion but I didn't include calling it.

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: GetPersonDirection??
Reply #10
@Rhuan: Want to see something awesome? (miniSphere only)

Code: (JavaScript) [Select]
let spritesets = from(new DirectoryStream('@/spritesets'))
    .where(it => it.fileName.endsWith('.rss'))
    .select(it => ({ fileName: it.fileName, spriteset: LoadSpriteset(it.fullPath) }));
for (let it of spritesets) {
    var convertedName = FS.fullPath(it.fileName, '@/convertedSpritesets');
    from(it.spriteset.directions)
        .each(it => it.name = it.name.toLowerCase());
    it.spriteset.save(convertedName);
}

:))
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

Re: GetPersonDirection??
Reply #11
@Rhuan It was the only function so I dropped it right into game and attempted it.
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Rhuan
  • [*][*][*][*]
Re: GetPersonDirection??
Reply #12
@Rhuan It was the only function so I dropped it right into game and attempted it.
Did you check the "other" folder afterwards? It will run very quickly and appear to do almost nothing but all the spritsets with updated names will be saved to the "other" folder and there as soon as sphere exits.

Also Sphere 1.5 or miniSphere? I haven't tested spriteset.save in miniSphere (it was added recently) so may be better to use 1.5 for this.

Re: GetPersonDirection??
Reply #13
Quote
Did you check the "other" folder afterwards? It will run very quickly and appear to do almost nothing but all the spritsets with updated names will be saved to the "other" folder and there as soon as sphere exits.

The "other" folder was empty.

Quote
Also Sphere 1.5 or miniSphere?

I tried it in both Sphere 1.5 & miniSphere.
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: GetPersonDirection??
Reply #14
@Rhuan At a quick glance your code uses slice() when it should use substr().  Maybe that's the problem?
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub