Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Lawrence

It is wrong to call "script.new" in a parallel process?

Question

Hello everyone, just made a simple script that controls when I push some buttons, to make it work, I made a common event with parallel process that constantly calls the "script.new", I wonder if that is a wrong way to constantly check something or no, can you help me?

Edited by Lawrence

Share this post


Link to post
Share on other sites

21 answers to this question

Recommended Posts

  • 0

you could use the update method to constantly check for something each frame? Can you let us see the script to assess what is needed to make it update on its own? Parallel processes tend to destroy your frame rate :P

Edited by drago2308

Share this post


Link to post
Share on other sites
  • 0

you could use the update method to constantly check for something each frame? Can you let us see the script to assess what is needed to make it update on its own? Parallel processes tend to destroy your frame rate :P

 

Sure, here's the script (it's a simple button control)

 

 

 

 

class X_buttons

  def initialize
    
    @MainCharacter = $game_party.actors[0]
    @PlayerName = $game_actors[1].name
    @Player = $game_actors[1]
    
    if Input.press?(Input::SHIFT) == true
      if $game_variables[10] > 0 
        $move ="@move_speed = 4"
        $game_player.instance_eval($move)
        case Input.dir4
        when 2,4,6,8
          @the_changing_sprite = "running"
          stamina_drain_running
          sprite_change
        when 0
          @the_changing_sprite = "nothing"
          sprite_change
        end
      else
        $move ="@move_speed = 3"
        $game_player.instance_eval($move)
        @the_changing_sprite = "nothing"
        sprite_change
      end
      
    else
      $move ="@move_speed = 3"
      $game_player.instance_eval($move)
      @the_changing_sprite = "nothing"
      sprite_change
    end

    if Input.press?(Input::CTRL) == true


    end

  end
  
  def stamina_drain_running
    
    if $the_running_timer >= 20 
      if $game_variables[10] > 0
        $game_variables[10] -= 1
      end
      $the_running_timer = 0
    else
      $the_running_timer += 1
    end
  
  end
  
  def sprite_change
    if @the_changing_sprite == "nothing"
      if @PlayerName == "001"
        @Player.set_graphic("Ch_001",1,"Blank",0)
        
        $game_player.refresh
      end
    elsif @the_changing_sprite == "running"
      if @PlayerName == "001"
        @Player.set_graphic("Ch_000",1,"Blank",0)
       
        $game_player.refresh
      end
    end

  end

end

 

 

Edited by Lawrence

Share this post


Link to post
Share on other sites
  • 0

The code doesn't seem to work in my test code eg, sprinting doesn't work you're just very slow. so i currently have no way to debug it. Since the code does not have dependencies on another class. eg. X_buttons < Window (this wont work just an example). I tried moving some of the code to a update but since it has no way to automatically run an update check on its own it turned out to be useless. Calling it like you did seems to be fine, it'll just take up a event space in your game. just remember the more events on a map the more laggy it will become.

Share this post


Link to post
Share on other sites
  • 0

The code doesn't seem to work in my test code eg, sprinting doesn't work you're just very slow. so i currently have no way to debug it. Since the code does not have dependencies on another class. eg. X_buttons < Window (this wont work just an example). I tried moving some of the code to a update but since it has no way to automatically run an update check on its own it turned out to be useless. Calling it like you did seems to be fine, it'll just take up a event space in your game. just remember the more events on a map the more laggy it will become.

 

Works on mine :/ bah

Anyway, can you give me an example of auto update script?

Share this post


Link to post
Share on other sites
  • 0

It needs to be extended from a base script. eg Quest_Marker < Sprite for it to have an auto update method inbuilt.

 

 

class Quest_Marker < Sprite

#------------------------------------------------------
# * Initialize
#------------------------------------------------------
def initialize
#initialize everything once
end

#-------------------------------------------------------------
# * Update Frame
#-------------------------------------------------------------
def update
Everything that needs updating per frame will be here
end
end

 

Share this post


Link to post
Share on other sites
  • 0

It needs to be extended from a base script. eg Quest_Marker < Sprite for it to have an auto update method inbuilt.

 

 

class Quest_Marker < Sprite

 

#------------------------------------------------------

# * Initialize

#------------------------------------------------------

def initialize

#initialize everything once

end

 

#-------------------------------------------------------------

# * Update Frame

#-------------------------------------------------------------

def update

Everything that needs updating per frame will be here

end

end

 

 

Thanks, I'll see what I can do :)

Share this post


Link to post
Share on other sites
  • 0

It needs to be extended from a base script. eg Quest_Marker < Sprite for it to have an auto update method inbuilt.

 

 

class Quest_Marker < Sprite

 

#------------------------------------------------------

# * Initialize

#------------------------------------------------------

def initialize

#initialize everything once

end

 

#-------------------------------------------------------------

# * Update Frame

#-------------------------------------------------------------

def update

Everything that needs updating per frame will be here

end

end

 

 

Ok so... I did something like:

class X_controls
  
  def initialize
  
    $Xbuttons = X_buttons.new
    
    
    loop do    
      
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    
  end
  
  def update
    $Xbuttons.update
    
  end
  
end

And results in "Stack level to deep" in line 5, ($Xbuttons...) what does that mean?

Edited by Lawrence

Share this post


Link to post
Share on other sites
  • 0

It says "Stack level too deep" because you try to open the script in the same script.

Also, this script is for running? I think a better way is to change/add stuff at "Game_Player" or something like that honestly.

 

Also, in your first script you've posted. the "(Input::SHIFT)" wouldn't work unless you got a keyboard script as the program has mapped Shift to another key (Not sure how to explain it). In RMXP it's "(Input::A)" for the shift key. If it did work for you without a keyboard script, then I am unsure how and what lol

Edited by Tigurus

Share this post


Link to post
Share on other sites
  • 0

It says "Stack level too deep" because you try to open the script in the same script.

Also, this script is for running? I think a better way is to change/add stuff at "Game_Player" or something like that honestly.

 

Also, in your first script you've posted. the "(Input::SHIFT)" wouldn't work unless you got a keyboard script as the program has mapped Shift to another key (Not sure how to explain it). In RMXP it's "(Input::A)" for the shift key. If it did work for you without a keyboard script, then I am unsure how and what lol

 

What do you mean "I'm trying to open the script in the same script"?

Share this post


Link to post
Share on other sites
  • 0

lol sorry disregard my last post for a bit, I am not fully awake.

Nonetheless, probably, somewhere is using $Xbuttons. If you try to make it all @Xbuttons.

That means it will become a local variable instead of global and while also be only used for that class, it won't get interrupted by the same variable.

Share this post


Link to post
Share on other sites
  • 0

lol sorry disregard my last post for a bit, I am not fully awake.

Nonetheless, probably, somewhere is using $Xbuttons. If you try to make it all @Xbuttons.

That means it will become a local variable instead of global and while also be only used for that class, it won't get interrupted by the same variable.

 

It does the same with "@"

 

I checked but there's no other x_buttons anywhere, so

maybe it's because in X_buttons I wrote

 

class X_buttons < X_controls

 

I'm not sure what "<" means in that case..

Edited by Lawrence

Share this post


Link to post
Share on other sites
  • 0

Uff... Ok so,

now I got this

 

 

 

class X_controls 
  
  def initialize

    loop do    
      
      update

    end
    
  end
  
  def update
    $Xbuttons.update
    #the $Xbuttons = X_buttons.new is now in the new_game command
  end
  
end

 

 

 

and then the running script, with "update" instead of "initialize"

 

 

 

class X_buttons
  
  def initialize
    #@MainCharacter = $game_party.actors[0]
    @PlayerName = $game_actors[1].name
    @Player = $game_actors[1]
  end
  
  def update
    
    
    
    
    if Input.press?(Input::SHIFT) == true
      
      if $game_variables[10] > 0 
        $move ="@move_speed = 4"
        $game_player.instance_eval($move)
        case Input.dir4
        when 2,4,6,8
          @the_changing_sprite = "running"
          stamina_drain_running
          sprite_change
        when 0
          @the_changing_sprite = "nothing"
          sprite_change
        end
      else
        $move ="@move_speed = 3"
        $game_player.instance_eval($move)
        @the_changing_sprite = "nothing"
        sprite_change
      end
      
    else
      $move ="@move_speed = 3"
      $game_player.instance_eval($move)
      @the_changing_sprite = "nothing"
      sprite_change
    end

    if Input.press?(Input::CTRL) == true


    end

  end
  
  def stamina_drain_running
    
    if $the_running_timer >= 20 
      if $game_variables[10] > 0
        $game_variables[10] -= 1
      end
      $the_running_timer = 0
    else
      $the_running_timer += 1
    end
  
  end
  
  def sprite_change
    if @the_changing_sprite == "nothing"
      if @PlayerName == "001"
        @Player.set_graphic("Ch_001",1,"Blank",0)
        
        $game_player.refresh
      end
    elsif @the_changing_sprite == "running"
      if @PlayerName == "001"
        @Player.set_graphic("Ch_000",1,"Blank",0)
       
        $game_player.refresh
      end
    end

  end

end

 

 

 

now a message appears: "The script is hanging".

Maybe it's a suggestion to hang myself, anyway, what am I doing wrong? :/

Edited by Lawrence

Share this post


Link to post
Share on other sites
  • 0

What the hell are you trying to do in the first place? What's your script supposed to achieve?

Share this post


Link to post
Share on other sites
  • 0

What the hell are you trying to do in the first place? What's your script supposed to achieve?

 

I'm trying to write a script to make the player run + drain stamina + change his sprite when holding SHIFT

 

It worked but to make it work I just put a parallel process with "script".new in it,

but it seems it's not the better way to do it so I'm trying to do that with "script".update

Edited by Lawrence

Share this post


Link to post
Share on other sites
  • 0

Why don't you just event it?

 

Ok I did it, but it is a safe way to check something?

I mean, it won't do errors while playing?

 

Sorry if I'm asking stupid things, but It's like running in the dark for me at the moment ^^"

Edited by Lawrence

Share this post


Link to post
Share on other sites
  • 0

Errr... Eventing can't give you errors (that's the point of eventing actually). Besides, while you can technically slow down the game using events you seriously need to fuck up your commands like a pure evil genius - which I'm sure you aren't, so you should be fine. And regarding "what else", well I'm returning the question.

 

I suggest you scout the internet for tutorials on how to event running upon pressing a button, there are a lot of them. I understand that you are trying to learn RGSS, which in itself is commendable. But you shouldn't expect immediate resutls from a piece of code you clearly don't understand the first thing about. We'll be glad to help you figure out discrete issues, but we can't provide you with an entire custom RGSS course, just to fit your own needs. Please come back to us after you've taken the time to make some research on your topic

Share this post


Link to post
Share on other sites
  • 0

Errr... Eventing can't give you errors (that's the point of eventing actually). Besides, while you can technically slow down the game using events you seriously need to fuck up your commands like a pure evil genius - which I'm sure you aren't, so you should be fine. And regarding "what else", well I'm returning the question.

 

I suggest you scout the internet for tutorials on how to event running upon pressing a button, there are a lot of them. I understand that you are trying to learn RGSS, which in itself is commendable. But you shouldn't expect immediate resutls from a piece of code you clearly don't understand the first thing about. We'll be glad to help you figure out discrete issues, but we can't provide you with an entire custom RGSS course, just to fit your own needs. Please come back to us after you've taken the time to make some research on your topic

 

Ok, thanks a lot for your patience ^^"

Share this post


Link to post
Share on other sites
  • 0

It's ok, we were all beginners at some point. I'm not shutting you out, just clarifying my point of view (and that of my fellow scripters, I'm pretty positive) before someone does.

Share this post


Link to post
Share on other sites
  • 0

Sounds like it is time to seriously study how to script...  For this, I'd recommend going of of the Game_Player class.

 

class Game_Player

  alias player_stamina_initialize initialize

  def initialize

    # Call Original Method or any other Aliases of Initialize

    player_stamina_initialize

    # New Property for Stamina

    @stamina = 1000

  end

 

  alias player_stamina_update update

  def update

    # Call Original Method or any other Aliases of Update

    player_stamina_update

    # Check for Scene Map (so it doesnt update while in Menus or Battle)

    return unless $scene.is_a?(Scene_Map)

    # Check for Interpreter (Events executing)

    return if $game_system.map_interpreter.running?

    # Check for the Player pressing buttons

    if Input.press?(Input::X)

      # Check for Stamina

      if @stamina > 1

        # Set Speed to Sprint Speed

        @move_speed = 5

        # Subtract from Stamina

        @stamina -= 1

      # Stamina Too Low

      else

        # Deafult Move Speed

        @move_speed = 4

      end

    # If not pressing button

    else

       # Default Move Speed

       @move_speed = 4

       # Increment Stamina to Max

       @stamina +=1 if @stamina < 1000

    end

  end

end

 

Untested like a boss...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...