Author Topic: Code isn't working  (Read 636 times)


function getRangeForZ(%z)
{
   %r = "0 10"; //
   while(inRange(%z,%r) == false)
   {
      %r = getWord(%r,0) + 10 SPC getWord(%r,1) + 10;
   }
   return %r;
}

function inRange(%z,%r)
{
   if(%z >= getWord(%r,0) && %z <= getWord(%r,1))
      return 1;
}

I dont know whats wrong with this, but this gets all forgeted up for some reason.
Any help would be great.

I can't determine what this is meant to do, thus I can't really help you.

Looks like some sort of depth indicator/checker, but unless you tell us what it's really for and what it's SUPPOSED to do and what it's NOT doing right, nobody can help you.

Also, ambig title much?

so
what
it should be doing
is finding the range %z is in, counting by tens
like
if z = 21
20 - 30
if z = 41,231
41,230 - 41,240


Terragen does something like this to round a player's location to the nearest 4x cube

I would suggest

function getrange(%z)
{
   %lwr = mfloor(%z/10)*10;
   %upr = %lwr + 10;
   return %lwr SPC %upr;
}

Unless I am going crazy and delusional again, this looks to me like it should do what you are asking.

I can't discern anything from this, but it doesn't look like that Nexus. It appears he's trying to raise a variable to be above another one. Not really sure what he's trying to do.

I literally went through your script as the game would do and had to figure out what you were doing that way. Jesus.

getRangForZ(50);

Then, this goes:
   %r = "0 10"; //
   while(inRange(50,%r) == false)
   {
      %r = getWord(%r,0) + 10 SPC getWord(%r,1) + 10;
   }

So it's in a loop checking range 50,%r until it's true.

   if(50 >= 0 && 50 <= 10)

50 is not <= 10, so this returns 0 (rather nothing, but oh well)

Back to the loop, increase first and second word by 10

   if(50 >= 10 && 50 <= 20)

Still nope.

   if(50 >= 20 && 50 <= 30)

Still nope.

   if(50 >= 30 && 50 <= 40)

Annddd. Nope.

   if(50 >= 40 && 50 <= 50)

Suddenly, yes! It returns "40 50".


So, what all this ends up doing is getting a range of 10 which the number lays between. What nexus said:

function getrange(%z)
{
   %lwr = mfloor(%z/10)*10;
   %upr = %lwr + 10;
   return %lwr SPC %upr;
}

would do:

%lwr = (50/10) * 10; //5 * 10 -> 50
%upr = %lwr + 10; // 50 + 10 = 60
return %lwr SPC %upr; //50 60


so, while they return different things they really do the same thing. Use Nexus'. It's way, way easier to comprehend and way, way easier on the game.

so
what
it should be doing
is finding the range %z is in, counting by tens
like
if z = 21
20 - 30
if z = 41,231
41,230 - 41,240
If z equals 40 is it in the range 40-50 or 30-40, because Nexus' script will return 40-50.