Common Event calling in scripts

Started by Memor-X, October 28, 2011, 02:43:55 am

Previous topic - Next topic

Memor-X

i've been working on a number of stuff for months lately, one of them is a small script, in it i had hoped to call common events, this is the code

class Test

def self.runFunction

@data_commonevent2 = load_data("Data/CommonEvents2.rxdata")

common_event = @data_commonevent2[1]

# If common event is valid
if common_event != nil
p "hello"
# Make child interpreter
@child_interpreter = Interpreter.new(1)
@child_interpreter.setup(common_event.list, 5)
p "hello2"
end

end
end


as you can obviously see, most of it i copied from Interpreter3, how it should work is that when you use the script call Test::runFunction(), it first loads a .rxdata file which is a copy of the CommonEvents.rxdata file, all it contains is 1 common event which has the show message event command, i have CommonEvents.rxdata have nothing for that same common event so i know that it's the common event of CommonEvents2 which is working when this function runs.

after that it just does what Interpreter3 does for common events (i can't remember the command number but i know it's in Interpreter3), anyway, when i run it, i get now error, hello and hello2 print out but the common event doesn't work, am i missing something in this script?

Fantasist

Hey Memor :D
I'll check this in detail later, but just to make sure, you're calling this on the map, right?
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Memor-X

Quote from: Fantasist on October 28, 2011, 02:56:26 am
Hey Memor :D
I'll check this in detail later, but just to make sure, you're calling this on the map, right?

yep for testing testing wise but i would have it in a parallel common event , the reason why i want to have a second .rxdata common event file is so i can keep a bunch of common events separate from the main game which are used in a separate cutscene viewer and for achievement notifications......

Fantasist

November 07, 2011, 03:16:41 am #3 Last Edit: November 07, 2011, 03:19:02 am by Fantasist
Why are you defining it as self.runFunction ? Interpreter operations are instance-specific, meaning calling your function as a module function won't work. Secondly, define your method in the Interpreter class itself and make use of @event_id and @depth variables, just to be safe. Here's my recommendation:


class Interpreter
 
  #--------------------------------------------------------------------------
  # * Call Common Event
  #--------------------------------------------------------------------------
  def call_common_event(id)
    # Get common event
    if @data_commonevent2.nil?
      @data_commonevent2 = load_data("Data/CommonEvents2.rxdata")
    end
    common_event = @data_commonevent2[id]
    # If common event is valid
    if common_event != nil
      # Make child interpreter
      @child_interpreter = Interpreter.new(@depth + 1)
      @child_interpreter.setup(common_event.list, @event_id)
    end
    # Continue
    return true
  end
 
end


Call it like this in a Script... event command:
call_common_event(<ID>)

In your example, ID is 1.

Regarding @event_id, is there any reason you replaced it with 5? @event_id is supposed to be the ID of the event calling the common event. 0 is for player. Since you're explicitly calling the common event through script, it would make more sense to use 0. Of course, I'd use @event_id, not a number, because it conforms to the default system.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Memor-X

i used 5 cause that was the id of the event i was using to test, i though the @event_id was used in event commands that used "This Event" and i had preset the depth value because there wasn't going to be any common event calling within a common event

thanks for the code though, i will have to change a small bit of it, just the data_commonevent2 so that i use an argument since it was only a test i was using a file called "CommonEvents2", in practical use, the file's name will reflect what data it holds like "BossProssessing001" or "CutscenesChapter1"

just make sure, when you say

Quote from: Fantasist on November 07, 2011, 03:16:41 am
Call it like this in a Script... event command:
call_common_event(<ID>)

In your example, ID is 1.


i can use that inside a script, the reason why i did the self. is because i was calling it as
Test::runFunction

just so i could test to see i could use the code in a script, in actuallality i would use

$testClass = Test.new
$testClass.runFunction


and the common event call script would be called in that function, i was just being lazy when making that test calss

Fantasist

Quotei used 5 cause that was the id of the event i was using to test, i though the @event_id was used in event commands that used "This Event" and i had preset the depth value because there wasn't going to be any common event calling within a common event

As far as I know, @event_id is ised even otherwise. The event has to run from somewhere, and @event_id contains the event on the map from which the command was called.

Quote
$testClass = Test.new
$testClass.runFunction

That will make a new Test instance every time you execute it. Besides, when there's an interpreter instance running, why not make use of it, especially since it makes more sense to call the code from the interpreter? ;)

Glad I helped, post if you need anything else.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Memor-X

Quote from: Fantasist on November 09, 2011, 09:07:42 am
Quotei used 5 cause that was the id of the event i was using to test, i though the @event_id was used in event commands that used "This Event" and i had preset the depth value because there wasn't going to be any common event calling within a common event
Quote
$testClass = Test.new
$testClass.runFunction

That will make a new Test instance every time you execute it. Besides, when there's an interpreter instance running, why not make use of it, especially since it makes more sense to call the code from the interpreter?


think i didn't make the code clear, if i use the Test Class as i would with the script i want to run common events from, the $testClass = Test.new would be located in the new_game function in Scene_Title and the $testClass.runFunction would be called when particular conditons have been met, so would
call_common_event(<ID>)

work within my code like this

your code (with edits)


class Interpreter
 
  #--------------------------------------------------------------------------
  # * Call Common Event
  #--------------------------------------------------------------------------
  def call_common_event(file,id)
    # Get common event
    if @data_commonevent2.nil?
      @data_commonevent2 = load_data(file)
    end
    common_event = @data_commonevent2[id]
    # If common event is valid
    if common_event != nil
      # Make child interpreter
      @child_interpreter = Interpreter.new(@depth + 1)
      @child_interpreter.setup(common_event.list, @event_id)
    end
    # Continue
    return true
  end
 
end



my testing code

class Test

def self.runFunction
call_common_event("Data/CommonEvents2.rxdata",1)
end

end


like i said, Test was mode just to test if it can be done, after i know this i'll implemented it in the real script


PS: the reason why i can't put up the original script is because it contains the source code for MARS (Memory Allocation Remapping System) which i have promised not to show to anyone (i didn't make it, my friend did)

Fantasist

All is good then :)
And MARS... I don't understand what it's supposed to do, but I won't press.

PS: I downloaded Nexis Core and it's patch, they were corrupted. I didn't redownload to make sure because they're big downloads. Could you check on your end? I'd like to check them out. :)
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Memor-X

Quote from: Fantasist on November 11, 2011, 03:46:51 am
PS: I downloaded Nexis Core and it's patch, they were corrupted. I didn't redownload to make sure because they're big downloads. Could you check on your end? I'd like to check them out. :)


the patch is only huge cause it's the encrypted archive, as i said in the description, i wanted to show off the game as it was when i submitted it into the competition and got my honorable mention, the patch fixes up bug i found while i was waiting on the results i'm hoping ARC will allow me to make smaller patches, reason why i was asking about a different encryption system for RMXP a while back

as for the corrupted files, i'll see what i can do, not sure how the files are corrupt, anyway, my net is shite, it'll take like an hour each for them (speaking of which, how the hell did i get them on there in the first place with my connection), so i might just to the game itself since you really won't miss much without the patch and see what's wrong with it, the next release for the game is another patch which gives Nexis Core: Chain of Shadows the ability to be used with Pandora, this topic is what i needed to help finish all the RMXP side of Pandora and Pandora itself should be done soon once i have MARS working in it, after that i just have to do a major site update including server uploads for Pandora (should take too long, just need to learn file U/I/O which i have soruce information for) and the patch is done

once i check out the main game installer i'll send you a PM if i fix it or what's going on

Fantasist

Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews