Conditional Branch Script Terrain Tag

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
331
Reaction score
90
First Language
English
Primarily Uses
N/A
I'm using

$gamePlayer.terrain_tag===1
but player keeps phasing over the tagged tiles without anything happening. So what's the correct script call?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
What's happening?
Machine only tells you what you tell it to do. It doesn't have any implicit knowledge as to what you want it to do. Therefore if you ask it to search for a wrong variable, it will search for wrong variable.
I can't tell you the exact name now, but search the core scripts for terrain and maybe you'll find out how terrain tags are called.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
$gamePlayer.terrainTag() === 1

I'm surprised that's not actually causing your game to crash, the way you have it. Unless there's a try/catch by default.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
@Shaz That's how javascript works.
If you have a top level variable that is undefined, Javascript reports an error and the game crashes.
If you have an undefined attribute of an object, Javascript, unlike Ruby or Python, is completely fine.
You just can't use methods or attributes of undefined methods or attributes.
For example:
You can't use terrainTag if it's not defined. Even if you try a code
Code:
if (!!terrainTag)
, which is supposed to convert the undefined value to false, JS will throw an error, because terrainTag is not defined.

Of course you can't use
Code:
$gamePlayer.terrainTag()
if it's not defined, because undefined is not a function.

However, using
Code:
$gamePlayer.terrainTag
is completely fine even if terrainTag is undefined. This is how JS handles potentially undefined attributes.

What is not fine though is
Code:
$gamePlayer.terrainTag.value

// or
$gamePlayer.terrainTag.setValue ()
if terrainTag is undefined. It will result in a crash.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
@Poryg - so $gamePlayer.terrain_tag is okay because it's a variable, even though it isn't defined, but you couldn't do $gamePlayer.terrain_tag() because it's a function call and the function isn't defined?

Talk about confusing! How do you pick up typos like the OP has made then - apart from the fact that the game doesn't do what you expect?
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
331
Reaction score
90
First Language
English
Primarily Uses
N/A
What's happening?
Machine only tells you what you tell it to do. It doesn't have any implicit knowledge as to what you want it to do. Therefore if you ask it to search for a wrong variable, it will search for wrong variable.
I can't tell you the exact name now, but search the core scripts for terrain and maybe you'll find out how terrain tags are called.
Alright, I'll check.

$gamePlayer.terrainTag() === 1

I'm surprised that's not actually causing your game to crash, the way you have it. Unless there's a try/catch by default.
I think you added a try/catch to your script, I used the ace-to-mv converter script.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
@Shaz Simple. It's exactly due to the fact that what I expect doesn't happen. Then I can open the console, print appropriate objects and see for example that a sprite's x is NaN. So that means I must have used an undefined variable for math.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I used the ace-to-mv converter script
The Ace-to-MV converter does not convert script calls. That's up to you to do. It does provide a list of all places where script calls are used, but you've got to fix them manually.

Ace uses $game_player; MV uses $gamePlayer.
Ace uses .terrain_tag; MV uses .terrainTag().
Ace uses ==; MV uses ===.

What you have there is a script call that's half Ruby and half Javascript. It looks like you started to do it manually, but only did part of it.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
MV uses both == and ===. == means is equal to in value and === means is identical to, in other words is equal both in value and in type. I use === only in cases when I need to find undefined variables though.

But yes, quite often in ruby the variables are typed like
$game_player
$game_actor

while in JS it's not _ with lowercase, but these two are replaced by an uppercase.

$gamePlayer
$gameActor
terrainTag instead of terrain_tag

and so on.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
331
Reaction score
90
First Language
English
Primarily Uses
N/A
The Ace-to-MV converter does not convert script calls. That's up to you to do. It does provide a list of all places where script calls are used, but you've got to fix them manually.

Ace uses $game_player; MV uses $gamePlayer.
Ace uses .terrain_tag; MV uses .terrainTag().
Ace uses ==; MV uses ===.

What you have there is a script call that's half Ruby and half Javascript. It looks like you started to do it manually, but only did part of it.
I know it doesn't convert script calls, that's why I have half JS - I've been trying to find the correct script call and only found part of it. Also, $gamePlayer.terrainTag()==1 works. Thank you for providing it.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I get confused with JS's == and === so I just use === all the time.

I know it doesn't convert script calls
I thought you were saying the converter did that :)

If you get stuck with something like that, you can always look for an event command that does it (in this case Get Location Info) and take a look at rpg_objects.js at the Game_Interpreter.prototype section way down at the bottom, and see what it does behind the scenes. In most cases, if you find Game_Interpreter.prototype (to get to the beginning of that class definition) you can then search for the exact text that shows on the event command button.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
331
Reaction score
90
First Language
English
Primarily Uses
N/A
I get confused with JS's == and === so I just use === all the time.


I thought you were saying the converter did that :)

If you get stuck with something like that, you can always look for an event command that does it (in this case Get Location Info) and take a look at rpg_objects.js at the Game_Interpreter.prototype section way down at the bottom, and see what it does behind the scenes. In most cases, if you find Game_Interpreter.prototype (to get to the beginning of that class definition) you can then search for the exact text that shows on the event command button.
No, I said your script must have a try/catch in it so wrong scripts don't crash the game.

I'll check out GI too.
 

Sauteed_Onion

Mmm Tasty
Veteran
Joined
Dec 13, 2017
Messages
554
Reaction score
3,665
First Language
English
Primarily Uses
RMMV
So much useful information for this subject.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
No, I said your script must have a try/catch in it so wrong scripts don't crash the game.
My script runs in Ace. It would have no effect on whether the command would crash in MV or not.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,854
Messages
1,016,998
Members
137,562
Latest member
tamedeathman
Top