Update/draw functions

Hi all. I've been trying to make some stuff happen in my game and I can see that the use of "Parallel Process" is starting to break things apart, meaning, some things work on some maps and in others don't. If there's like too many (in my case around 4-5 ) events some stuff just don't work right. To fix all that I want to start adding stuff direct to the update/draw function on the player/event as needed. Starting with the player I saw that there's a update function (for input and calculating stuff) and a refresh one that I assumed it's related to drawing on screen. So this is what I had:

[IMG]https://dl.dropboxusercontent.com/u/22813242/Help/stealth.PNG[/IMG]

So I started doing this:

[IMG]https://dl.dropboxusercontent.com/u/22813242/Help/stealth2.PNG[/IMG]

Is this the best (read right) place to this sort of edit, or there's a better one or one you guys would recommend for this kinda stuff?
I dont understand what you want to do exactly?

Do you want to convert your Events into RGSS?

And where you place your edit depends on what exactly you want to do.

So you want to make a stealth system?
I dont understand what you want to do exactly?

Do you want to convert your Events into RGSS?

And where you place your edit depends on what exactly you want to do.

So you want to make a stealth system?
I was just wondering where was the right place to add that piece of code. If I should add to a "draw" function or to the update one. Just some guidance. I ended up adding directly to the update as you see. Yeah I'm working on a stealth game. I was avoiding scripting but I'm slowly adding code there since the performance and usability improves a lot.
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

Your event has some issues, and that's what's causing the lag. Fix those, and you won't have to resort to scripts at all.

Try changing your event to something like this (I don't see you do anything with player's direction, so I don't see the point in using it at all):

Code:
Control Variables: [0002: Player_X] = Players Map XControl Variables: [0003: Player_Y] = Players Map YGet Location Info: [0001], Region ID, Variable [0002][0003]Comment: HAS the region changed?  We dont want to be changing opacity/screen tint to a value that it is already at, every frameConditional Branch: Variable [0001: Region ID] == Variable [0004: Last Region ID]  Jump to Label: NoChangeElse  ... add the conditional branches, player opacity, and screen tints that youve already got in hereBranch EndLabel: NoChangeComment: Add a WAIT.  EVERY parallel process that runs continuously should have a wait at the start/end (as well as within long loops) to avoid lagWait 5 Frames
oops - looks like the new forum software is trying to be clever with comments and stuff, and it makes the code look ugly. Ignore my misspellings of Player's, don't and anything else that should have a ' but doesn't.
Yeah it was lagging pretty bad. I moved to the players update as I said and it's funny that doesn't lag there even If I don't check if the region changed. A parallel process works as a logical thread right?
It was lagging because, on every iteration, you were telling it to do a screen tint that took 3 frames to complete, even if you didn't NEED to do it. And once it was done, because you had no Wait, it was telling it to do it again immediately afterwards. You were hardly ever giving it a chance to do other stuff.


I would be really interested to see you change your parallel process to what I've described above, temporarily comment out your script changes, and see how much of a difference it makes.


Parallel processes SHOULDN'T cause much lag, but you have to be smart about how you design them. This is why I'd like you to try it. It's lagging because there's a couple of flaws in your design. The better approach would be to figure out what they are and fix them, rather than modifying scripts to compensate.
Yeah you're completely right Shaz! This parallel process was really broken, I mean, I had others happening at the same time but no problem with it. Anyhow posting how it turned out:

[IMG]https://dl.dropboxusercontent.com/u/22813242/Help/stealingsyst2.PNG[/IMG]

Though I think I'll stick with the scripting version just for the sake of using less variables, really.

Code:
if region_id == 2  @opacity = 155   $game_map.screen.start_tone_change(Tone.new(-52, -52, -52,  0), 1)elsif region_id == 3   @opacity = 125   $game_map.screen.start_tone_change(Tone.new(-80, -80, -80,  0), 1)else   @opacity = 255   $game_map.screen.start_tone_change(Tone.new(0, 0, 0,  0), 1)end
That control variables to set variable 14 to the current region (which I forgot to do, so good pickup) should be done immediately after the conditional branch to compare them (as soon as you know they're different, set the 'last region' to the current region id, since it's not used anywhere else. That just makes your event a little shorter, rather than doing it in every internal condition.


So do you still need more assistance with the script version, or is it all good now?
That control variables to set variable 14 to the current region (which I forgot to do, so good pickup) should be done immediately after the conditional branch to compare them (as soon as you know they're different, set the 'last region' to the current region id, since it's not used anywhere else. That just makes your event a little shorter, rather than doing it in every internal condition.

So do you still need more assistance with the script version, or is it all good now?
Yeah I should have done just after the condition! No man I think I'm good 🙂 Thanks for the help! 

Original thread: https://forums.rpgmakerweb.com/threads/update-draw-functions.18276/