Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MKXP handles array pointer arguments differently than RMXP #177

Open
LockeZ opened this issue Oct 1, 2017 · 3 comments
Open

MKXP handles array pointer arguments differently than RMXP #177

LockeZ opened this issue Oct 1, 2017 · 3 comments

Comments

@LockeZ
Copy link

LockeZ commented Oct 1, 2017

I have a method in one of my game scripts as such:

def self.event_comment_input(*args)
    elements = *args[0]
    trigger = *args[1]
    ...
    etc.
end

It's called from elsewhere in the script with a line like:

event_comment_input(25, 'Destructable')

In RPG Maker XP's default Game.exe, this causes the variable "elements" to be set equal to 25, and the variable "trigger" to be set equal to 'Destructable'. The variables are an integer and a string.

However, in MKXP's Game.exe, this causes the variable "elements" to be set eqal to [25], and the variable "trigger" to be set equal to ['Destructable']. The variables are arrays.

For now, I can handle this by simply having my script check if MKXP is in use, and setting elements = elements[0] and trigger = trigger[0] if so. It's not a big deal for me personally, since I only have one method in one script using this syntax. However, this would be a major problem in some games, and took me about an hour to figure out what was going on.

I'm not sure which behavior is actually correct for a Ruby compiler, but it's probably best for MXKP to exhibit the same behavior as RMXP even if it's wrong.

@carstene1ns
Copy link
Contributor

Ruby is not C, there are no pointers and you can only pass by value.
The * (splat) operator does not dereference here, but is used for Array coercion:
https://endofline.wordpress.com/2011/01/21/the-strange-ruby-splat/
The use of the splat operator has changed between 1.8 and later versions, in 1.8 you could use it to flatten an array (which worked in your example), so either RMXP and MKXP behaviour is fine here, regarding the different ruby versions.

@Ancurio
Copy link
Owner

Ancurio commented Oct 1, 2017

Likely a Ruby change that happened in the 1.8 → 1.9 transition. When I finally get around to merging that PR for builds with MRI 1.8 this should be alleviated.

Does simply using args[0] and args[1] not work correctly under RMXP?

@LockeZ
Copy link
Author

LockeZ commented Oct 2, 2017

It probably does. Might even be simpler in this case, but part of this script was written for me by someone else, and I'd rather avoid messing with it any more, now that I've gotten it working, in case there is a reason for why it's done that way.

I'm sure there are ten other ways these arguments could be written that would work the same in both pieces of software. The issue isn't the inability to code a working program, just the inability to run ones that already exist.

Splendide-Imaginarius added a commit to Splendide-Imaginarius/mkxp that referenced this issue Mar 22, 2024
…zos-blitting

Don't use framebuffer blitting if shader-based interpolation is needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants