iPhone App Directory
RPG Maker VX
 
Gallery Members Search Calendar Help


Welcome Guest ( Log In | Register )

Collapse

>Announcement

Keep an eye out for the upcoming 3rd Quarter Contest!
 
Reply to this topicStart new topic
> How do I call something from a script?
MegaDethKlok
post Feb 17 2012, 12:13 AM
Post #1



Group Icon






Hey guys. I'm making a game (Was posting on this site like, 3 years ago, please ignore those posts as I was terrible back then) and I'm using it to learn a little ruby, bit by bit.

Now, I understand this forum is mainly/entirely for RMVX, but my question is for RMXP and should work for both of them. I have a script that uses activation skills, like say your POW stat is 30 points, you could set the activation rate for a particular skill to your POW stat, and that would give you a 30% chance of activating that skill. Now, I want there to be the "default" activation rates in my scripts, and then have a special "bonus map" with the activation rates set high so other people can see and play with the cool skill animations for themselves. To do this, I've determined I want to have an event on the map that uses the script command to be used as a single map editor, but I don't know the syntax to use. This is complicated, so here are pictures as a demonstration.

I want to call the starting portion of this script here...


and put it into an event for me to modify, like this kind of, but obviously I'm not doing it correctly.

(Ignore everything except the line "ACTIVATION_CHANCE =" and lower)


If I'm not being clear enough, I can try to explain further. Also how do I still have a 20% warning after 3 to 4 years lolol

This post has been edited by MegaDethKlok: Feb 17 2012, 12:14 AM


--------------------
Go to the top of the page
 
+Quote Post
   
FlipelyFlip
post Feb 18 2012, 09:48 AM
Post #2


Arr teh Pirate
Group Icon


Type: Musician
Alignment: Neutral Good




heyey,

the mistake you made is easy. when you do this:

ACTIVATION_CHANCE = {
bla => bla
}

you add all the stuff in between the bricks to the array.

Try this:
ACTIVATION_CHANCE[DEMON]
ACTIVATION_CHANCE[FLARE]
...

Do it with all the things you want to call, it should work then (:

~Flip
Go to the top of the page
 
+Quote Post
   
MegaDethKlok
post Feb 18 2012, 06:52 PM
Post #3



Group Icon






So then I would say
ACTIVATION_CHANCE[DEMON] = "self.pow"
or uh
ACTIVATION_CHANCE[DEMON]"self.pow"
?

Whups I just realized what you meant by "In between the bricks", my bad.

This post has been edited by MegaDethKlok: Feb 19 2012, 06:09 AM


--------------------
Go to the top of the page
 
+Quote Post
   
MegaDethKlok
post Feb 20 2012, 02:13 AM
Post #4



Group Icon






Actually it turns out it's not working for me. Uhm here's what I have so far.



Neither changes at all, any ideas?


--------------------
Go to the top of the page
 
+Quote Post
   
Mithran
post Feb 20 2012, 12:33 PM
Post #5


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




The you are looking for is:

CODE
hsh[key] = value


or

CODE
ACTIVATION_CHANCE['PIERCE'] = 'self.pow * 10'


ruby-doc.org is a good reference for these sorts of things.

However, I would caution against this for a few reasons. The first is that you are modifying a constant during runtime. While this is technically possible, it is generally bad practice and depending on the script implementation it could be a constant for a reason. Which brings me to #2, depending on the implementation of the script, the constant may not even be referenced anymore by the time you alter it (it could use some runtime evals, it might have parsed through the entire hash and defined methods for each once and only once). So if nothing changes, this could be the reason why.

Additionally, constants are bound to the current instance of the program and therefore if you were to enter this map (activating the event) then save, then load the game, your constant would be back to the original values (unless the event is run again).

So, this brings me to a slightly cleaner implementation. Since it looks like the values of the ACTIVATION_CHANCE are going to be eval'd at some point, just put your branch in there. For example, the line:

CODE
'PIERCE' => 'target.pdef'


becomes:

CODE
'PIERCE' => '$game_switches[50] ? self.pow * 10 : target.pdef'


Assuming switches are implemented in XP as they are in VX, the result of the function when evaluated would be power times 10 if switch 50 is on, and the targets physical defense if the switch is off, allowing you to flip a switch and change all the formulas. You could also change the switch conditional to a map conditional, but as I have never used XP I don't know what method to call to determine the current map's ID and/or name, and I would recommend asking that particular question on an appropriate board. If you have further questions about the Ruby implementation, feel free to ask here.


--------------------
Go to the top of the page
 
+Quote Post
   
MegaDethKlok
post Feb 20 2012, 06:03 PM
Post #6



Group Icon






Ah, that is perfect man. Thank you so much for that help, it's what I've been needing soooo bad biggrin.gif

My biggest issue is, I have ADHD and Dyslexia, so I have a very hard time learning anything new, and coding is just so complex for me. You explained it exactly the way I need to hear, I can easily flip a switch no problem. I'll test it and if it works, you're my hero.

Edit: I got it working, I didn't realize at first I had to put your revision into the actual scripts (Not in an event) and it came out looking like this. Thanks a bunch smile.gif



This post has been edited by MegaDethKlok: Feb 20 2012, 07:19 PM


--------------------
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 30th September 2014 - 12:57 PM

RPGMakerVX.net is an Privacy Policy, Legal.