Help with scene manager call

Hello everybody!

I created this method to be called from the damage formula of one item

Spoiler
class Game_Battlerdef eat_level_up(b,min,max,n) if b.level < min SceneManager.goto(Scene_Map) #close item menu to display message $game_message.add("This item is too much powerful!") $game_party.gain_item($data_items[n], 1) elsif b.level > max SceneManager.goto(Scene_Map) #close item menu to display message $game_message.add("This item is not powerful enough!") $game_party.gain_item($data_items[n], 1) else SceneManager.goto(Scene_Map) #close item menu to display level up b.change_level(b.level + 1, true) end i=0 while (i==0) # Wait for user to close message, then return to Scene_itemWait(1)break if Input.press?🙂Z)endSceneManager.call(Scene_Item)return 0end #end moduleend
The damage formula passes target, minimum value, maximum value and item id.

It all works quite good until the Wait part, it neither waits for an input nor returns to scene item,

if I removed  the while part it would call scene_item immediately, and the player could not see the message until the menu is manually closed,

what did I do wrong?  >_>

By the way, the item can only be used used from menu, and not in battle.

Also, is there a difference between SceneManager.call and SceneManager.goto? I tried both.
The wait method typically takes an amount of time in frames, and there are typically 60 frames per second. Here, you're only waiting 1 frame, or 1/60th of a second. Try using 60.

Edit: SceneManager.call puts the starts the next scene and put the previous one in a list so we can return to it later. SceneManager.goto skips the part where we put the last scene in a list, and just starts the new one. Say we called SceneManager.goto(Scene_Menu). If we pressed escape to return to the previous scene (SceneManager.return), then we wouldn't go back to the map, the game would close because there is no last scene, and the engine is set up that if there isn't a scene, close the game.
Thanks for the answer!

I tried changing wait(1) to 60 but it still doesn't work, it seems to skip everything after "while (i==0)"

how can I create a loop that breaks when the player closes the message text?
while is bad >_> , I mean you can use while, but you need to be VERY VERY careful with it x).


what probably happens is that the Scene is not updated, there are some approaches to make this work, some are better coded and others are kind of not really suggested.


You can put the message directly by creating a Window class on Scene_Item and putting the message through the Window created, istead of going back to the map and again to the item scene, I think this is the best clean mode to do this.


If you really do need to go to the Scene_Map, you can just put a verifier on the Window_Message class, when a message with the text "This item is too much powerful!" is shown and then closed I call Scene_Item, this is the method of the Window_Message to put that condition : def close_and_wait


Another way, the worse xD, but you probably can get the result you do want, call SceneManager.scene.update on the while.


I think this things will work for you 🙂 , Ah and it is method, module is another thing x).
I really confused method with module?  >_>

I ended up using a $game_temp.reserve_common_event(1) instead of that while loop, and using a loop inside the common event, but your suggestion of using Window class to avoid closing the menu  is surely more elegant, I will try that  🙂 , Thank you!

Edit: I'm having some problem trying to display the level up message during the scene_item, can you help me please? 🤔  
Ah, yeah that is a little harder x), can you update your code?


because you can use the b, which is your actor to call its name like, b.name, and its level b.level to create the full string xD something like.


draw_text_ex(x, y, b.name + " grown to level " + b.level.to_s + "!")


or the same above but more cleaner..


draw_text_ex(x, y, "#{b.name} grown to level #{b.level.to_s} !")
I'm probably doing something very stupid...

Please don't mind the coordinates, I will adjust them as soon as I get the message to show up

Spoiler
 
Code:
class Game_Battler#=============================================================================  def eat_level_up(b,min,max,n)#============================================================================= if b.level < minstring = "This item is too much powerful!"$game_party.gain_item($data_items[n], 1)elsif b.level > maxstring = "This item is not powerful enough!"$game_party.gain_item($data_items[n], 1)elseb.change_level(b.level + 1, false)string = "#{b.name} is now level #{b.level.to_s}!"endWindow_Base.Eaty_Message(string)#============================================================================= end    # Method end#============================================================================= end
Ok I managed to make the message show up  during scene_item 

Spoiler
class Scene_Item < Scene_ItemBase #-------------------------------------------------------------------------- # * Start Processing #-------------------------------------------------------------------------- def start super create_help_window create_category_window create_item_window create_message_window end #-------------------------------------------------------------------------- # * Create Message Window #-------------------------------------------------------------------------- def create_message_window @message_window = Window_Message.new end 
But if I press ok to close the window it simultaneously use the same item again, how can I deactivate temporarily the other windows of the Scene_Item (@item_window) ?
@item_window.deactivate should do the trick.
Ehm sorry Trihan, where do I put it exactly? I tried both at the start and the end of the script

Spoiler
class Game_Battler#============================================================================= def eat_level_up(b,min,max,n)#============================================================================= if b.level < min$game_message.add("This item is too much powerful!")$game_party.gain_item($data_items[n], 1)elsif b.level > max$game_message.add("This item is not powerful enough!")$game_party.gain_item($data_items[n], 1)elseb.change_level(b.level + 1, true)end@item_window.deactivate#===================================end #method end#============================================================================= end
or do I have to use it inside scene_item class?

Edit: ok solved, I had to check for $game_message.visible inside this method

def use_item return if $game_message.visible play_se_for_item user.use_item(item) use_item_to_actors check_common_event check_gameover @actor_window.refresh endOf Scene_ItemBase

Original thread: https://forums.rpgmakerweb.com/threads/help-with-scene-manager-call.38725/