Maldra

Veteran
Veteran
Joined
May 31, 2017
Messages
90
Reaction score
10
First Language
English
Primarily Uses
RMMV
Hey all,

I'm attempting to code a hookshot into my game. I'm currently getting a variable for the player's location X and the player's location y, as hookshot location x and hookshot location y. I will be using terrain ID and get location info for most of the coding, but that does not take into account of events that may be in the way. Because of this I am trying to implement a comparison of the event's location x and y and compare them.

I first tried comparing the event and hookshot's x and y variables, but it will not work properly unless the two are merged. For example, if the event's x and the hookshot's x = each other the code would not run properly, meaning there is an entire row and an entire column where the code won't run, even though I only want it for the one location.

Because of this, I would like to try to merge the two variables--simply adding them together won't solve anything because say for example you have x=1 and y=4, it would be the same as x=4 and y=1. Can anyone assist me with merging the variables? (Or maybe you've got another idea that would work?)

Here are the lines of code I am having issues with:
$gameVariables.value(11) == $gameVariables.value(9) + $gameVariables.value(10)
$gameVariables.value(12) == $gameMap.event(9).x + $gameMap.event(9).y
$gameVariables.value(11) != $gameVariables.value(12)

upload_2017-10-13_23-6-18.png

Thanks in advance for the help! :)
 

bhindi1224

NOT Indian Okra
Veteran
Joined
Sep 19, 2017
Messages
295
Reaction score
168
First Language
English
Primarily Uses
RMMV
Is there a way to convert them into a string and compare that string? I don't know much about java scripting, but that shouldn't be too difficult I would think. Your string might be "x34y45" and then you could check both the axes with one variable. So in short convert both the x and y location numbers into a text string and combine them that way using a separator.
 

Maldra

Veteran
Veteran
Joined
May 31, 2017
Messages
90
Reaction score
10
First Language
English
Primarily Uses
RMMV
Yeah, that's what I meant :) I guess I forgot to use the word "string", though. I had read that a simple + was supposed to merge two strings together, but it wasn't working.
 

bhindi1224

NOT Indian Okra
Veteran
Joined
Sep 19, 2017
Messages
295
Reaction score
168
First Language
English
Primarily Uses
RMMV
Forgive my ignorance if I"m just not getting it, but is this what you need to do?
concat()
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,693
Reaction score
3,023
First Language
Tagalog
Primarily Uses
RMVXA
If you do want to combine them, you would need to set the variable via the Script command for control variable and for example save them as an array [X,Y]. Then you'd also use the Script part of the conditional branch to check them in one go

OR

. I had read that a simple + was supposed to merge two strings together, but it wasn't working.

It's because the values of $gameVariables are numbers by default and not strings, so using $gameVariables.value(v1) + $gameVariables.value(v2) would actually merge them mathematically, so basically add them via mathematical methods.. If you want to combine them as string, do this
String($gameVariables.value(v1)) + String($gameVariables.value(v2)) so that the game converts them to string first before combining them

Note: Change v1 and v2 to the ID of the variables that you need
 

Maldra

Veteran
Veteran
Joined
May 31, 2017
Messages
90
Reaction score
10
First Language
English
Primarily Uses
RMMV
If you do want to combine them, you would need to set the variable via the Script command for control variable and for example save them as an array [X,Y]. Then you'd also use the Script part of the conditional branch to check them in one go

OR



It's because the values of $gameVariables are numbers by default and not strings, so using $gameVariables.value(v1) + $gameVariables.value(v2) would actually merge them mathematically, so basically add them via mathematical methods.. If you want to combine them as string, do this
String($gameVariables.value(v1)) + String($gameVariables.value(v2)) so that the game converts them to string first before combining them

Note: Change v1 and v2 to the ID of the variables that you need


Yes, I think an array is probably what I need, actually. I was just thinking about it and the same issue I mentioned earlier could come about with combining them as strings. Example: x=1, y=12 = 112 would be the same as x=11, y=2 = 112.

Do you have any tips for setting up arrays? I can always google about them too :)
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,693
Reaction score
3,023
First Language
Tagalog
Primarily Uses
RMVXA
You could do

$gameVariables.set(ID,[Variable for X, Variable for Y]) so for your post,

$gameVariables.set(11,[$gameVariables.value(9), $gameVariables.value(10)])

or you could always just put a comma or something else in the string combination

String($gameVariables.value(9)) + "," + String($gameVariables.value(10))

That way, x=1,y=12 will be 1,12 while x=11,y=2 will be 11,2 so they won't be the same anymore
 

Maldra

Veteran
Veteran
Joined
May 31, 2017
Messages
90
Reaction score
10
First Language
English
Primarily Uses
RMMV
You could do

$gameVariables.set(ID,[Variable for X, Variable for Y]) so for your post,

$gameVariables.set(1,[$gameVariables.value(9), $gameVariables.value(10)])

or you could always just put a comma or something else in the string combination

String($gameVariables.value(9)) + "," + String($gameVariables.value(10))

That way, x=1,y=12 will be 1,12 while x=11,y=2 will be 11,2 so they won't be the same anymore

Cool, I will try that! Thank you!!!
 

Maldra

Veteran
Veteran
Joined
May 31, 2017
Messages
90
Reaction score
10
First Language
English
Primarily Uses
RMMV
You could do

$gameVariables.set(ID,[Variable for X, Variable for Y]) so for your post,

$gameVariables.set(11,[$gameVariables.value(9), $gameVariables.value(10)])

or you could always just put a comma or something else in the string combination

String($gameVariables.value(9)) + "," + String($gameVariables.value(10))

That way, x=1,y=12 will be 1,12 while x=11,y=2 will be 11,2 so they won't be the same anymore

It is working! However, I have come into another crossroads. I am trying to write a script to check for all the events in one call, but am trouble with the switch comparison. Can you help with my syntax?

((String($gameVariables.value(9)) + "," + String($gameVariables.value(10)) != String($gameMap.event(9).x) + "," + String($gameMap.event(9).y)) || ($gameSwitches.Value(35) === true))

This is a conditional script i am calling. I am trying to have it say if the variables 9 and 10 do not equal the event location OR if switch number 35 is true, it will run the rest of the code.

Thanks in advance! :)
 

Maldra

Veteran
Veteran
Joined
May 31, 2017
Messages
90
Reaction score
10
First Language
English
Primarily Uses
RMMV
Nvm!!!! I figured out what was causing the problem! Apparently the syntax does not allow a capital V in value, and when i switched it to a lowercase it is now working correctly :)
 

Latest Threads

Latest Posts

Latest Profile Posts

Hi everyone! Enjoying this nice long weekend. How are you all doing? :)
I just successfully tested having events check if specific actors are in a particular party slot and then changing image to match. This will let me make scenes take into account who is in the party at the time and arrange them accordingly - this is important since I'll have extra actors beyond current party. The script used is the same from MV and is compatible with my current core plugin setup in MZ. Thank goodness.
That awkward moment when you're talking about thinking about writing a limited shop stock plugin for MZ and then find out you already wrote one...last May. My memory is so bad.
When I open my project and I'm like, hell yeah.
Some drawings I made in Lapis, one day I intend to involve them in some RPG Maker project.
* maybe two wall frames
*or some sprite flower tiara, or maybe it inspires someone to do something.
bdd19b62e539d17b3b00cc3d63034f7d.jpg

fcca5c8471b34483da8e032cfe579275.jpg

Forum statistics

Threads
118,426
Messages
1,115,859
Members
155,377
Latest member
L4TNG
Top