Scripts / script to work on multible objects

Author
Message
Team wolf
7
Years of Service
User Offline
Joined: 26th Dec 2016
Location:
Posted: 17th Jan 2017 16:56 Edited at: 17th Jan 2017 16:58
i made this script every time the entity gets damage it scales up i declared some globals but the problem is that applyes to all the entities that are using this script how can i have these globals to be independant for every entity.so i can use the same script on multiple entityes?

PM
Pirate Myke
Forum Support
14
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 17th Jan 2017 18:20 Edited at: 17th Jan 2017 18:22
make them local variables instead in the script. Dont have the syntex for you on that. but I am sure it wont be long till someone replies to you.

This post explains it better.
https://forum.game-guru.com/thread/215687#msg2551611
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

Team wolf
7
Years of Service
User Offline
Joined: 26th Dec 2016
Location:
Posted: 18th Jan 2017 05:32
Local varibles work but i need a seperate script for eatch entity.i need a way to work multiple entityes with one script
PM
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 18th Jan 2017 08:34
Quote: "Local varibles work but i need a seperate script for eatch entity.i need a way to work multiple entityes with one script"


That's exactly what local variables are supposed to do, if you have say "local bob = 0" in a script that has say a line that if you click E when within range of the entity it changes local bob to 1, then you can put the same script on two different entities and when you press E next to one it will change local bob to 1 for only that entity, the other entity with the same script will still be local bob = 0 until you walk up to it and press E, that's the whole point of the local variables, they only change on the entity they're on.

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Jan 2017 09:52
Use a list, i.e. at the top of the script have <variable_name> = {}

Then to set the variable use <variable_name>[e] = <value>.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Jan 2017 10:04
Not quite belidos, locals are still used across multiples of the same script, only an array/list will let you use the same variable for multiple objects using the same script (or changing the variable at runtime so it can get changed to the value for that entity using it at that time).
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 18th Jan 2017 11:58
Quote: "Not quite belidos, locals are still used across multiples of the same script, only an array/list will let you use the same variable for multiple objects using the same script (or changing the variable at runtime so it can get changed to the value for that entity using it at that time)."


OK, so i'm confused now, i thought local was as i explained, and global was for sharing variables across entities, what exactly is the differecne between local and global then?

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
Team wolf
7
Years of Service
User Offline
Joined: 26th Dec 2016
Location:
Posted: 18th Jan 2017 13:46
Locals are local for the same script so if you have a vairiable with the same name in the other script it will not be effected.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Jan 2017 15:26
Indeed, it's about the name of the script (which is why naming functions and scripts the same is so very important)....
A global will/can be accessed by any script (a good example of this is the "pressed" variable you see in a lot of scripts that need the 'e' key to trigger something, this is global because you want the pressed to toggle for all objects so that only 1 is triggered (without further checking this would technically be the entity with the lowest entity number), no matter how many objects are checked.

If you take the above and set 2 scripts (named differently) on 5 objects each and both scripts have "pressed" defined but as a local instead of a global then assuming all objects were simply checking for "pressed" (and all other conditions are true) then 1 of the first 5 would be triggered AND 1 of the second group of 5 too (this will be true for all groups so for example having a local "pressed" in a door and also in an object you wanted to collect could let you open the door and collect the object with the same press.

Hope that clears it up for you
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 18th Jan 2017 15:51 Edited at: 18th Jan 2017 15:53
Quote: "Hope that clears it up for you "


Not really lol. Did a grand job of giving me a headache though

Seriously though. Let me see if i got this straight.

Local is for if you want one variable that can be used individually on different scripts in different entities.

So for example, if i had three doors, in doors one and two put example1.lua which has a local variable "local open =", in door three i put example2.lua in it, this script also has the same variable in it "local open =". If i trigger the variable in door one, then both door one and two will open, but three will not, if i trigger the variable in door three, then door three will open but the others wont..

But, if i was to change it in all the scripts to "global open =" then triggering any of the three doors variables would open all three..

Is that right?

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Jan 2017 18:03
Yep
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Jan 2017 19:20 Edited at: 18th Jan 2017 19:24
Another important point about local variables is that they only exist whilst in scope whereas global variables are retained (unless you specifically set them to 'nil' then they are gone).

So if you define local inside a function when the function ends the variable and anything it was storing can be freed up.

Where this becomes important is with things like sprites, when you do something like this


The dome_img variable will be thrown away at the 'end' statement and the memory used freed up (at least it should if Lee has done it right . )

The dome_sprites variable otoh is global so will live until you no longer require it when you can do 'dome_sprites = nil' and it should then be freed up.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-23 04:00:57
Your offset time is: 2024-12-23 04:00:57