RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Request] Using a script call to change a picture

0 Members and 1 Guest are viewing this topic.

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
My event code for a flashy image reveal in a common event:
Spoiler for herp:

My thoughts on having to do this upwards of 200 times for each possible outcome of my item reel:
Spoiler for derp:

What this does is display an image, then have a ghost of that image expand around it, disappearing as it increases in size. I wanted to make this effect occur three times, but the tedium reduced my desire to making it happen once. It looks good, but...pasting this over and over seems bloaty AND retarded. If I could event the animation once, and change the picture it uses with a quickie script call, I feel like that would be LOADS better.

Can I perhaps store the image id in a variable, call that variable with a script line, and use it to replace whatever image 2 and 3 are?

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
I'm fairly new to scripting, so hopefully this helps out in some way. I made a quickie script that should work ... except for the fact that @wait_count is not making the script wait like it should. If someone could add in how to call a wait, this script should emulate exactly how you had your common event set up. I think.

class AniGrow
  def self.grow_outline(aImg = [])
    # aImg = [nLayer, szName, nPos, nX, nY, nGrowPlus, nOpacNeg, nWait]
    # nPos <0 Left-Corner, 1 Center>

    if aImg != nil
      nGrow = 100  #100% Size
      nOpac = 255  #Fully Visible
   
      while nOpac - aImg[6] > 0
        $game_map.screen.pictures[aImg[0]].show(aImg[1], aImg[2], aImg[3], aImg[4], nGrow, nGrow, nOpac, 0)
        nGrow += aImg[5]
        nOpac -= aImg[6]
        @wait_count = aImg[7]
      end
     
      $game_map.screen.pictures[aImg[0]].erase
     
    end
  end
end


You'd call it in an event like so :

Nm = 'pic-name'
# Or : Nm = $game_variables[nVar]
# Game variables can be text, just don't tell the debugger
# $game_variables[nVar] = 'pic-name'
aImg = [1, Nm, 1, 250, 250, 50, 35, 60]
AniGrow.grow_outline(aImg)
« Last Edit: June 12, 2011, 07:55:49 PM by Exhydra »

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Good thinking Exhydra, but the reason it isn't quite working is that you have it all inside a loop and you aren't updating Graphics.

It would be easy to fix, but in this case I think an eventing solution is better. Despite its name, Move Picture actually works for Zoom and opacity as well, so all you really need to do, Arrow, is:

@>Show Picture: 2, '0_sub_1', Center (316, 217), (100%, 100%), 255, Normal
@>Show Picture: 3, '0_sub_1', Center (316, 217), (100%, 100%), 255, Normal
@>Move Picture: 2, '0_sub_1', Center (316, 217), (135%, 135%), 0, Normal, @10, Wait
@>Erase Picture: 2

It is a nice effect though!

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
I actually had a long talk with Arrow on how to do this, and we discovered some stuff in Game_Interpreter.
Command 231 (show picture) has a number of parameters (like all the commands) to work off of. We pinpointed the @params[2] was the parameter that holds the filename of the picture.
So, if we alias the method and call it, then make @params[2] equal a predefined variable we could find a way to make this work.
This is what I'm talking about:
Code: [Select]
class Game_Interpreter
  alias i_love_arrow command_231
  def command_231
    i_love_arrow
    @params[2] = $game_variables[VARIABLE_NUMBER]
  end
end
Yeah?
It probably would be less confusing through eventing, but he did request a script. You'd also need a way to call the script properly, because as that is there it wouldn't do anything.
EDIT:: Exhydra had a good idea too. I'll take a look at it later more in-depth.
it's like a metaphor or something i don't know

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
I don't know what your method would really accomplish. For one thing, you'd have to modify the @params array prior to running i_love_arrow for it to have any effect. For another, he doesn't want to change the picture - he wants to change zoom and opacity. Moreover, that method would still require repeated calls of the show picture, though you could probably use a loop and simple variable commands so it would make it slightly easier.

I assume that he requested a script because he didn't know a better way to do it through events than the repeated show pictures. Given that a single Move Picture command is sufficient for the purpose, I doubt he will insist on a scripted solution that is harder to use. That said, it was smart of you to look at the Game_Interpreter class.

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
Well, this request evolved a bit while we were talking, and that's what we both agreed on. I had to leave though, so I didn't have much time to think about the script that much. But yes, you are right (as always).
I thought Arrow was a competent enough eventer to get what you were getting at ;_;
it's like a metaphor or something i don't know

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
There ... now the darn thing works! I continued work on it as a personal challenge.
It's basically a gimpy and staggered Move Picture event, but I was just sticking with the original request. I learned a few things along the way, so it's worth it.

Code: [Select]
class AniGrow
  def self.wait(duration)
    for i in 1..duration
      $scene.update_basic
    end
  end
 
  def self.grow_outline(aImg = [])
    # aImg = [nLayer, szName, nPos, nX, nY, nGrowPlus, nOpacNeg, nWait]
    # nPos >> 0 Left-Corner, 1 Center
   
    nGrow = 100
    nOpac = 255
   
    if aImg != nil
      while nOpac - aImg[6] > 0
        $game_map.screen.pictures[aImg[0]].show(aImg[1], aImg[2], aImg[3], aImg[4], nGrow, nGrow, nOpac, 0)
        nGrow += aImg[5]
        nOpac -= aImg[6]
        wait(aImg[7])
      end

      $game_map.screen.pictures[aImg[0]].erase
     
    end
  end
end
« Last Edit: June 13, 2011, 10:03:28 AM by Exhydra »

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
I don't know what your method would really accomplish. For one thing, you'd have to modify the @params array prior to running i_love_arrow for it to have any effect. For another, he doesn't want to change the picture - he wants to change zoom and opacity. Moreover, that method would still require repeated calls of the show picture, though you could probably use a loop and simple variable commands so it would make it slightly easier.

I assume that he requested a script because he didn't know a better way to do it through events than the repeated show pictures. Given that a single Move Picture command is sufficient for the purpose, I doubt he will insist on a scripted solution that is harder to use. That said, it was smart of you to look at the Game_Interpreter class.

No no, I did want to change the picture. I can run the event code, I just wanted to be able to, based on a variable, change what picture it was using. Then I have the code evented once, not hundreds of times, see. Having the actual animation in the script is convenient, sure, but the main thing was that I wanted to be able to change files.

If possible: would someone mind modifying this script to do only that? Because a snippet for that function would have myriad uses.

EDIT: Forgot to say this because I'm a tool, but thanks EVERYONE for helping me out. :D
« Last Edit: June 13, 2011, 06:12:10 PM by Arrow-1 »

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Ah, if you just want to change the picture based on a variable, then that's super easy.

Code: [Select]
class ExPicture
  def self.show_img(aImg = [])
    # aImg = [nLayer, szName, nPos, nX, nY, nhScale, nwScale, nOpac]
    # nPos >> 0 Left-Corner, 1 Center

    if aImg != nil
      $game_map.screen.pictures[aImg[0]].show(aImg[1], aImg[2], aImg[3], aImg[4], aImg[5], aImg[6], aImg[7], 0)
    end
  end
end


Calling it in an event would look like this :

Code: [Select]
Nm = $game_variables[nVarA]
aImg = [3, Nm, 1, 316, 217, 100, 100, 255]
ExPicture.show_img(aImg)

Nm = $game_variables[nVarB]
aImg = [2, Nm, 1, 316, 217, 100, 100, 255]
ExPicture.show_img(aImg)


nVarA and nVarB are the variables where the file names of your images would be, no extension needed (Example : $game_variables[1] = "Title").
« Last Edit: June 13, 2011, 07:21:21 PM by Exhydra »

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
I'm having an issue with it...forgive my ignorance.

My files are named with numbers. For instance, all items are 0, 1, 2, onward, and weapons are 101, 102...you get the point. I tried setting it up like this:

Code: [Select]
$game_variables[2] = "0"

Nm = $game_variables[2]
aImg = [3, Nm, 1, 316, 217, 100, 100, 255]
ExPicture.show_img[aImg]

Nm = $game_variables[2]
aImg = [2, Nm, 1, 316, 217, 100, 100, 255]
ExPicture.show_img[aImg]

And it doesn't like that. Says something about no implicit conversion from nil to an integer..? Happens with and without quotes around the zero.
« Last Edit: June 13, 2011, 07:06:04 PM by Arrow-1 »

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Yeah, I noticed that after I posted it. It took me a little while before I realized that I used '[ ]' instead of '( )' when calling the method. Sigh. I changed the code in the above post, it should be : ExPicture.show_img(aImg)

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
I'm still getting the error. Says it comes up on line seven. did I set this up wrong?

If it helps, in this instance it will always be drawing its data from variable number two.

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Hmm, it seems to work alright on my end and I copied the code and script calls over to a new project because I'm paranoid. Just make sure that you're not using '[ ]' instead of '( )' when you call the method.

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
Ah, it definitely works now. :D So then, I have a question. Is there a way to make it turn a number into a string? I can see this being useful for say, if I have some sort of a radar. It could check the location of a player, versus the objective, and then say oh the player needs to move in direction 6, and display a corresponding image.

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
nVar.to_s

The '.to_s' should convert the number/variable into a string, or dies trying.

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
Excellent! This works perfectly! Thanks for the new omni-tool, Exhydra, I really do appreciate it.