Jump to content




Calling from tables and using loops

peripheral help

7 replies to this topic

#1 OnyxFox

  • Members
  • 21 posts
  • LocationIn a cave.

Posted 11 August 2015 - 08:43 PM

I'm trying to find an easier way to add items to my HUD with OP terminal glasses using loops and tables to shorten my code and time to write things in.
Check out function Dis(), it won't let me call my arguments.
Any general suggestions/tweaks are welcome.

Code

Also in function updateDis() I had a for loop to fire off all of the Dis() functions.
for i=1,#P do
    Dis(P [ i ] )
end
I realize this won't work because it is calling a table but I'm still looking for a work around.

#2 Twijn

  • Members
  • 119 posts

Posted 11 August 2015 - 09:00 PM

I am assuming that you're trying to get whatever the variable tName is in the Table, and I believe that this would be getting "tName" from the table (which is nil).

Try to use P[tName][1]

#3 OnyxFox

  • Members
  • 21 posts
  • LocationIn a cave.

Posted 11 August 2015 - 09:55 PM

I added that and it still returned nil

#4 Twijn

  • Members
  • 119 posts

Posted 11 August 2015 - 10:00 PM

View PostOnyxFox, on 11 August 2015 - 09:55 PM, said:

I added that and it still returned nil

On the last part you added, you can do this:

for i,v in pairs(P) do
  --do stuff here. Note that "i" would be what it's called (time,bridge,lava,mana) and v would be the tables
end


#5 OnyxFox

  • Members
  • 21 posts
  • LocationIn a cave.

Posted 11 August 2015 - 10:11 PM

View PostTwijn, on 11 August 2015 - 10:00 PM, said:

View PostOnyxFox, on 11 August 2015 - 09:55 PM, said:

I added that and it still returned nil

On the last part you added, you can do this:

for i,v in pairs(P) do
  --do stuff here. Note that "i" would be what it's called (time,bridge,lava,mana) and v would be the tables
end

Ok so
for i,v in pairs(P) do
  Dis( i )
end
?

And the nil value is still returning in the first line of the Dis() function.
It doesn't like the P[tName][1]

Edited by OnyxFox, 11 August 2015 - 10:13 PM.


#6 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 11 August 2015 - 10:46 PM

View PostOnyxFox, on 11 August 2015 - 10:11 PM, said:

View PostTwijn, on 11 August 2015 - 10:00 PM, said:

View PostOnyxFox, on 11 August 2015 - 09:55 PM, said:

I added that and it still returned nil

On the last part you added, you can do this:

for i,v in pairs(P) do
  --do stuff here. Note that "i" would be what it's called (time,bridge,lava,mana) and v would be the tables
end

Ok so
for i,v in pairs(P) do
  Dis( i )
end
?

And the nil value is still returning in the first line of the Dis() function.
It doesn't like the P[tName][1]

Obviously it doesn't like it because you give it nil in the first place. At the bottom of the code, where you actually call Dis() you should put the arguments into "'s.

Also you could shorten the if-block for bridgeS: bridgeS = mess and" Open" or "Closed"
If you don't know how/why this works, you should read about the ternary operator.

Edited by H4X0RZ, 11 August 2015 - 10:50 PM.


#7 OnyxFox

  • Members
  • 21 posts
  • LocationIn a cave.

Posted 12 August 2015 - 01:47 AM

View PostH4X0RZ, on 11 August 2015 - 10:46 PM, said:

Obviously it doesn't like it because you give it nil in the first place. At the bottom of the code, where you actually call Dis() you should put the arguments into "'s.

Also you could shorten the if-block for bridgeS: bridgeS = mess and" Open" or "Closed"
If you don't know how/why this works, you should read about the ternary operator.

Ok that fixed it. However function updateDis() no longer repeats.

Updated Code


#8 OnyxFox

  • Members
  • 21 posts
  • LocationIn a cave.

Posted 12 August 2015 - 02:16 AM

This is the working script from before I started trying to consolidate it.
Spoiler






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users