Problem with making a certain part of my AI

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,897
Reaction score
2,864
First Language
French
Primarily Uses
RMMV
Hi people I work on my AI and this begin to works wells

just for not confuse people this not a Battle AI but a Scene AI who create a character who react on your action 

here the thread : 

http://forums.rpgmakerweb.com/index.php?/topic/40656-nkea-basic-ai-module-v01-beta/#entry405217

now I work on the multiple personality 

if I explain each "ai" can have is own personality and each dialogues 

when a ai_id is not define it will take in consideration the default dialogues : 

AIV_Default ={ :vendor_graphics => "", :greeting => "", :good_bye => "", :buy_goods_dialogues => "what you want to buy?", :sell_goods_dialogues => "", :not_buying_dialogues => "", :not_selling_dialogues => "", #not yet :haggle_goods_dialogues => "", :suceed_haggles_dialogues => "", :fail_haggles_dialogues => "", #not yet implemented :good_reputation_greeting => "", :bad_reputation_greeting => "", :kick_out_shop_dialogues => "", :patience => 100 }
now everything's works fine just I stuck is the Personality parts I can't retrieve the text it's always stuck to say "nil" when I msgbox_p

I will show the part I used to create the personality stuff but I will still send you the complete scripts link 

http://pastebin.com/PHwAF8MY

so here the section I used for program 

the configuration zone in waht I want to look like : 

AI_Personality ||= { } # do not touch! AI_Personality[1] ={ :vendor_graphics => "", :greeting => "", :good_bye => "", :buy_goods_dialogues => "text", :sell_goods_dialogues => "", :not_buying_dialogues => "", :not_selling_dialogues => "", #not yet :haggle_goods_dialogues => "", :suceed_haggles_dialogues => "", :fail_haggles_dialogues => "", #not yet implemented :good_reputation_greeting => "", :bad_reputation_greeting => "", :kick_out_shop_dialogues => "", :patience => 100 }
and what I programmed by getting refference to venka crafting script : 

def self.setup @ai_id = ai_id @ai_personality = AI_Personality[@ai_id] end def self.buy_goods_dialogues # if !as_personality? # @buy_goods_dialogues = default_AI[:buy_goods_dialogues] # else @buy_goods_dialogues = @ai_personality[:buy_goods_dialogues]# endendstrangely it's always show "nil" when I try to output the text with a msgbox_p (I still work on the message system)

so I hope people will be able to help me out because I really block on this part and this somewhat a important part of my script :)

thanks for any further answer!
 
Last edited by a moderator:

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,897
Reaction score
2,864
First Language
French
Primarily Uses
RMMV
I will bump this thread because it's 72h I wait for this to be answered

like I said I don't want you to do the script at my place just to help me out with this lines of codes : 

AI_Personality ||= { }I want to know by using this technique HOW to retrieve my string I have implemented in it ...
 

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
Whats ai_id in this line? Does it have a value?

@ai_id = ai_idYou could try do something like this:

AI_Personality ||= Hash.new{AIV_Default} # do not touch!so if you for example try to get AI_Personality[2] which isn't defined it would use your default values from the AIV_Default hash.
 
Last edited by a moderator:

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,897
Reaction score
2,864
First Language
French
Primarily Uses
RMMV
Whats ai_id in this line? Does it have a value?

@ai_id = ai_idYou could try do something like this:

AI_Personality ||= Hash.new{AIV_Default} # do not touch!so if you for example try to get AI_Personality[2] which isn't defined it would use your default values from the AIV_Default hash.
1 : aid_id permit to make the system know WICH Personality to choose it's the number in the  AI_Personality[ai_id]

but I mess up this one a little I guess :/

2 : damn this remove so many useless code lines just by doing this!  but I checked the technique from Venka crafting script and let me show you how she do this :

def initialize @craft = [] clear_results init_recipes end #---------------------------------------------------------------------------- # ○ new method: [] #---------------------------------------------------------------------------- def [](craft_id) return nil unless Venka::Crafting::Craft_Info[craft_id] @craft[craft_id] ||= Game_Craft_Info.new(craft_id) end #--she will initialize the "array" by doing this so this will get the method...but it's seem so messy....

I mean  I begin to think it's will complicate my script for nothing and just by doing this you have to pass by Instance calls....

if you know a better way for build my AI_personality I will take it with pleasure!

but I don't want to be forced or force people to use this technique even if this the easiest

Code:
def self.personalitycase personality_typewhen 1return kairenwhen 2return carlelsereturn defaultendend
 

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
The ||= is nothing else than a shortcut for

test || test = 1234This will just return test if test is initialized, otherwise it will initialize test and return the initialized value.

The problem is, that I don't understand what your exact problem is, so its somehow difficult to help you properly.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,897
Reaction score
2,864
First Language
French
Primarily Uses
RMMV
The ||= is nothing else than a shortcut for

test || test = 1234This will just return test if test is initialized, otherwise it will initialize test and return the initialized value.

The problem is, that I don't understand what your exact problem is, so its somehow difficult to help you properly.
and this a little hard for me to explain...

okai left me make a full example and I will try to explain as my best D:
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
811
First Language
Hungarian
Primarily Uses
RMVXA
In your setup method, the 'ai_id' local variable is not set anywhere, therefore it is 'nil'.


So, you set your instance variable to 'nil' indeed...


You must define a value for that 'ai_id' before you set your instance variable.


The easiest way would be to add an argument for that setup method, and pass an ID for it when you call the method.


And this would be equal to Venka's method in it's function.


Venka's method is not hard to understand if you know what this line means:

def [](craft_id)This is a method to get a specific data from an array/hash. You can see these methods in "wrapper" classes even in some default scripts (like Game_Switches, Game_Actors, etc).
The method itself is inserted into a class which holds many instances of a different class.


For example, when you call $game_actors[3], you trigger the same kind of method on the Game_Actors class, and the method itself will return an instance of Game_Actor class. If no Game_Actor instance has been initialized with the ID of 3, it will be created, if it is already initialized, it returns the current state of it.


I personally like that method and used in many of my scripts. Especially handy if you need to save your instances.


Anyway, add an argument for your setup method, call the method at the right place, pass an ID for the argument, and you are good to go.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,897
Reaction score
2,864
First Language
French
Primarily Uses
RMMV
thanks man! it's seemed so hard for me to understand but thanks this mean a lots : D

it's sure I am not sure how to really setup this but I decided to rewritte the scripts instead of putting a module I decide to use a class who seem more easier to do ...I will follow venka method but it's was just confuse me in begin :/

but thanks sixth : D

I made in following what you say and following the wrapper from the variable by doing this

in what I understand now I will be able to do the the thing? EVEN if I don't need the value thing haha

here the code

Code:
#==============================================================================# ■ Game_Personality#==============================================================================#==============================================================================# ** Game_Personality#------------------------------------------------------------------------------#  This class handles Personality_id. It's a wrapper for the built-in class #"Array." The instance of this class is referenced by $game_Personalities.#==============================================================================class Game_Personality  #--------------------------------------------------------------------------  # * Object Initialization  #--------------------------------------------------------------------------  def initialize    @personality =[]  end      #--------------------------------------------------------------------------  # * Get personality_id  #--------------------------------------------------------------------------  def [](ai_id)    @personality[ai_id] || 0  end  end
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

We'll be doing another giveaway of MZ on the stream tomorrow! Thank you SykoGaming for contributing a copy for the community! :D
Sorry guys! Been away for long this time. Got attacked by my anxieties again. At least no more bedbugs. Got logged out of here and layout seems strange now a bit.
My old project is now a sitcom
How to do implementation the social politcal mechanics in rpg maker? Thank you for quick spark of ideas. Fear of going to the thread lol.

Forum statistics

Threads
100,781
Messages
979,464
Members
132,419
Latest member
memakegamemekillminority
Top