Team Spartan Cookies & Milk Forums
Starfall Help - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html)
+--- Forum: Starfall (https://teamscm.co.uk/forum-7.html)
+--- Thread: Starfall Help (/thread-937.html)

Pages: 1 2 3 4 5


Starfall Help - Alanzote - 24-05-2015

1- Is there like a if(changed()) in Starfall?

2- Is there a way to select all entitys in an Array and execute a command in them?(Such like setSubMaterial?)

Thank you for your attention,
Alanzote.


RE: Starfall Help - Person8880 - 24-05-2015

(24-05-2015, 07:36 PM)Alanzote Wrote: 1- Is there like a if(changed()) in Starfall?
Forget everything about how E2 works. You don't need if (changed()), if (clk()) etc. as everything's event driven.

If you want to detect changes to wire inputs, you use the "input" hook. Other things you should also be using events for, you'll have to post exactly what you want to do for me to be able to give you the right events to use.

(24-05-2015, 07:36 PM)Alanzote Wrote: 2- Is there a way to select all entitys in an Array and execute a command in them?(Such like setSubMaterial?)
If your array of entities is called Ents, then:
for i = 1, #Ents do
local Ent = Ents[ i ]
--Do whatever it is you want to each entity in here, e.g
EntConfusedetSubMaterial( 0, "cmats/light" )
end



RE: Starfall Help - Blackhawk - 24-05-2015

1) No there isn't.

2)Yes use a for loop:

local Array -- your array with entities
for I=1, #Array do -- loop through all objects in your array
Array[I]ConfusedetSubMaterial(0, "material name") -- you can replace setSubMaterial by any other function for entities
end

EDIT: Person was faster lol


RE: Starfall Help - Alanzote - 24-05-2015

Thanks! =)

(24-05-2015, 08:00 PM)Person8880 Wrote:
(24-05-2015, 07:36 PM)Alanzote Wrote: 1- Is there like a if(changed()) in Starfall?
Forget everything about how E2 works. You don't need if (changed()), if (clk()) etc. as everything's event driven.

If you want to detect changes to wire inputs, you use the "input" hook. Other things you should also be using events for, you'll have to post exactly what you want to do for me to be able to give you the right events to use.
But I am not using a local and I need to see if it changed, so How do I do that?


RE: Starfall Help - Person8880 - 24-05-2015

Explain exactly what you are tracking for changes. It's rarely a good method when you're checking a global value for changes.


RE: Starfall Help - Alanzote - 24-05-2015

(24-05-2015, 08:12 PM)Person8880 Wrote: Explain exactly what you are tracking for changes. It's rarely a good method when you're checking a global value for changes.
I want to check if the var Alert Changed.

EDIT: In the loop thing I get: "attemp to index a nil value"


RE: Starfall Help - Person8880 - 24-05-2015

What sets the value? What needs to watch it for changes?

If you're setting the value yourself, then you can just run the code that needs to run when it's changed at the point you set the value.

For the nil value, post exactly what you have for the loop and the array.


RE: Starfall Help - Alanzote - 24-05-2015

(24-05-2015, 08:20 PM)Person8880 Wrote: What sets the value? What needs to watch it for changes?

If you're setting the value yourself, then you can just run the code that needs to run when it's changed at the point you set the value.

For the nil value, post exactly what you have for the loop and the array.
When you start the chip, the value is 0 and by chat commands the value is changed.

EDIT:
NIL PROBLEM

timer.create("Alert", 0.5,0, function()
if Alert == 1 then
for I = 0, #Corridors do
Corridors[I]ConfusedetSubMaterial(5, "phoenix_storms/pack2/redlight")
end
end
if Alert == 0 then
for I = 0, #Corridors do
Corridors[I]ConfusedetSubMaterial(5, "models/debug/debugwhite")
end
end
end)



RE: Starfall Help - Person8880 - 24-05-2015

Ok, instead of checking the value for changes (an E2-ism, not a good thing in Starfall), try this:
function ChangeAlert( NewAlert )
Alert = NewAlert
--Run stuff that needs to happen when alert changes here
end
This way you don't need to be checking for changes, and you can happily change the alert anywhere in the code with ChangeAlert().

As for the nil value problem, Lua "arrays" (arrays are just tables with number keys in Lua) start at index 1, not 0. So you need to start I from 1.


RE: Starfall Help - Person8880 - 24-05-2015

Read my last sentence again.

You have:
for I = 0, #Corridors do
you should have:
for I = 1, #Corridors do