Main Menu
  • Welcome to The RPG Maker Resource Kit.

[Request] Using a script call to change a picture

Started by Arrow, June 12, 2011, 07:52:49 AM

0 Members and 1 Guest are viewing this topic.

Arrow

My event code for a flashy image reveal in a common event:
[spoiler=herp]
[/spoiler]

My thoughts on having to do this upwards of 200 times for each possible outcome of my item reel:
[spoiler=derp]
[/spoiler]

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?

exhydra

#1
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)

UPDATED 05-29-14


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

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

modern algebra

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!

pacdiggity

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: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

modern algebra

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.

pacdiggity

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

exhydra

#6
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.

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

UPDATED 05-29-14


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

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

Arrow

#7
Quote from: modern algebra on June 13, 2011, 01:22:55 AM
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

exhydra

#8
Ah, if you just want to change the picture based on a variable, then that's super easy.

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 :

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").

UPDATED 05-29-14


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

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

Arrow

#9
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:


$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.

exhydra

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

Arrow

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.

exhydra

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

Arrow

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.

exhydra

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

Arrow

Excellent! This works perfectly! Thanks for the new omni-tool, Exhydra, I really do appreciate it.