Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# simultaneous executions?

Featured Replies

I'm trying to set up my Strobes Mod to support multiple cars; the problem I'm running into is if I try stuffing the cars list into an array/list and then executing the strobes off of that, the strobes go off in sequence rather than simultaneously on all the cars. I've tried setting up multi-threading with a parallel.foreach loop but so far all that's managed to do is crash my game each time, so either I'm doing that wrong or it's not entirely a good idea. Any thoughts on other possible ways to set up simultaneous execution?

  • Author

The pseudocode is

Foreach(car in the array)

{ strobeson }

void strobeson

{ while (car exists && car lights are on)

{ turn headlights on

wait

turn headlights off

repeat for number of flashes

}

}

I've tried using a parallel foreach loop to execute strobeson but that only seems to freeze the game up.

The pseudocode is

Foreach(car in the array)

{ strobeson }

void strobeson

{ while (car exists && car lights are on)

{ turn headlights on

wait

turn headlights off

repeat for number of flashes

}

}

I've tried using a parallel foreach loop to execute strobeson but that only seems to freeze the game up.

That's because you are using foreach.

try this...

foreach(car in array)

{strobeson}

wait

foreach(car in array)

{strobesoff}

void strobeson

{

turn headlights on

}

void strobesoff

{

turn headlights off

}

That should do it.

also you are doig alot of 'waiting' here...

that WILL freeze your game. Find a better way of utilizing a tick instead of using 'wait' think about it for 20 mins and you'll figure it out :)

Edited by rushlink

Community director, www.lc-gaming.net

  • Author

Wait() doesn't have any affect on the game performance as far as I've seen, all it does is pause that specific function. As for separating the on/off function, it's faster but I'm not sure it's exactly simultaneous since it still goes through the array in sequence. I imagine perfect simultaneous activation would need something other than a foreach loop.

Do wait(10000000) see what happens.

You could put it into a perframedrawing instead of a tick. then it would update them all on one frame. as far as it not being simultaneous, i think you may be mistaken as to how the game works with the scripthook.

The game will essintally pause while your script runs (per tick). Have you actually tested anything in game?

Community director, www.lc-gaming.net

  • Author

In fact, I just tested wait(1000000). It paused the script for 1000000 milliseconds and had no other affect on the game whatsoever. And yes, this script has been tested in game. In fact, v1 was released almost a week ago...

I think YOU may be mistaking about how Scripthookdotnet works.

Shown from the way you were trying to code this to start with... i'm fairly sure i have more of a grip on it than you do.

I mean... you were wondering why they were being processed linearly, and you had them in a foreach loop. That's covered in the first few days of a programming class buddy.

You are asking how to process them a the same time. This is nearly impossible on todays computers. On a single core pc it "is" impossible.

how are you running your script?

Are you using a tick? per frame drawing? how?

I'm 90% certain that in a tick if you tell it to wait, it holds up the game until the request is processed.

in per frame drawing im 99% certain it does.

Edited by rushlink

Community director, www.lc-gaming.net

Okay. Stop it right now with debating who knows more about how scripting works. It's stupid and doesn't get anywhere.

I am reasonably sure that Wait() won't pause the game in a tick. Looking at the GTA natives, it knows what threads are, and I am quite certain that SHDN runs scripts in threads. One nice thing about threading is that threads can pause without crashing the game. Per frame, it may hold the frame until it's done.

Remember that SHDN scripts are a step removed from the game. SHDN manages them, and can do stuff to help keep them from messing with the game. For example, it can deal with many script crashes gracefully (whereas ASI scripts with errors just crash the game). Keeping waits from pausing the game seems like something it would do.

Maybe it was in perframedrawing. Its been a while since ive had a problem like that.

But back to the orignial question.

Does anyone have any other suggestions?

Possibly putting his script into a perframe drawing would make it so the lights all flash at once as it processes that part of the script each time a frame is drawn?

Edited by rushlink

Community director, www.lc-gaming.net

What's the flash pattern? Is it like:

H P H P B P B P

where H = headlight flashes, B = blinker flashes, P = pause for a tiny bit?

To put it another way:

Headlight flashes twice, blinker flashes twice, time between headlight flash and blinker flash is the same as time between 2 headlight flashes?

  • Author

Never mind, I've sorted it myself. No point asking for any more help with this if all I get is someone telling me that their programming education is superior to my self-taught knowledge or that my script somehow causes massive lag despite not having had a single report of it whatsoever since release.

Edited by Kit

  • Management Team

The RAGE scripting engine doesn't allow multi threading access and why should it? You would have to acquire and release ownership before using a resource such as a vehicle so you can be sure it's not being disposed by another thread while using it. This would be ridiculous.

Edit: I'm glad you sorted it out.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

Never mind, I've sorted it myself. No point asking for any more help with this if all I get is someone telling me that their programming education is superior to my self-taught knowledge or that my script somehow causes massive lag despite not having had a single report of it whatsoever since release.

How'd you solve it?

This is a support topic.
Only reply here to offer help or assistance to Kit. Off-topic or "me too" replies will be removed.

Need support yourself? Make a new topic instead.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.