• The For Loop, help.
    4 replies, posted
Hello Facepunch, I'm looking for some help regarding my issue with the For Loop. it's to do with a little test I'm doing. I'm doing this because I was to get more in depth and I really do like learning too. What I'm trying to do is when the 'Player press E' on a table ( the table is an entity ) it'll then start spawning money ( the money is just an entity ) and everytime i press E it'll keep stacking on the table, BUT if the money is stacked too high, it'll make a new column I'm really unsure if I should use the 'For Each Loop' or the 'For Loop' to do this. I appreciate all your helps. Thank you.. Also, if someone could tell me why people add 'true or false' to this table below. [LUA] Group = { ["Admin"] = false, ["SuperAdmin"] = true, } [/LUA]
The table thing is done so you can do Group["Admin"] instead of table.HasValue(Group, "Admin").
[QUOTE=Chickengbs;51186521]Hello Facepunch, I'm looking for some help regarding my issue with the For Loop. it's to do with a little test I'm doing. I'm doing this because I was to get more in depth and I really do like learning too. What I'm trying to do is when the 'Player press E' on a table ( the table is an entity ) it'll then start spawning money ( the money is just an entity ) and everytime i press E it'll keep stacking on the table, BUT if the money is stacked too high, it'll make a new column I'm really unsure if I should use the 'For Each Loop' or the 'For Loop' to do this. I appreciate all your helps. Thank you.. Also, if someone could tell me why people add 'true or false' to this table below. [LUA] Group = { ["Admin"] = false, ["SuperAdmin"] = true, } [/LUA][/QUOTE] Throw the for loop idea out. There is no use for it here. Using the while loop would be better. I actually would just use a timer.create instead. Like so local function putmoneyonthetable () timer.create("MoneyTable", 1(How many seconds, lets say you want 1 bill to spawn every second.), 1(how many times should timer.create run), function(money) type in your code here for money to spawn on the entity and make it collide and stick and whatever bullshit. end) end And now you can call that function everytime you want to put money on the table. So for instance, you go into your table entity and have this while money on the table is < than the max amount of money allowed on the table do now we put an if function in the while loop. *Side note for the explanation I am about to write.* Make it so that the colmuns are saved when they are made. For example, you have colmun 1 and money is stacking, when colmun 1 gets high enough, you start on colmun 2. You would have ent.colmun = 1 or 2 or whatever colmun it is on. So now the if function. (The current colmun x should be defined when it starts, so like the script starts running, and column x is defined as 1. Once it is done, it will be defined as column 2. Etc etc.) local function addcolumnnumber (num) ent.column = ent.column + num end if amountofbillsin colmun x > specified amount then addcolumnnumber(1) do the check again or add money. You can make this check and the add column check seprate functions and just have them run over and over again until it works. end end Not sure if you understand what I am saying but basically have a defined column number, check if they money can stack in that column(if the column has already reached maximum capcity in holding bills) and if it can then add a bill. If all the columns are taken then just have it wait. Maybe just make a whole timer for it that never stops and keeps checking. I dunno, I feel like I got more and more incoherent but if you understood it then great, if you didn't then I dunno what to tell you.
[QUOTE=sannys;51186556]The table thing is done so you can do Group["Admin"] instead of table.HasValue(Group, "Admin").[/QUOTE] Adding to this, there's no need to add false ranks, adding a false rank and not adding it at all provides the same results (Assuming you use it in an if statement)
[QUOTE=sannys;51186556]The table thing is done so you can do Group["Admin"] instead of table.HasValue(Group, "Admin").[/QUOTE] Thank you, big help! [editline]11th October 2016[/editline] [QUOTE=FlyPiggyBanks;51186660]Throw the for loop idea out. There is no use for it here. Using the while loop would be better. I actually would just use a timer.create instead. Like so local function putmoneyonthetable () timer.create("MoneyTable", 1(How many seconds, lets say you want 1 bill to spawn every second.), 1(how many times should timer.create run), function(money) type in your code here for money to spawn on the entity and make it collide and stick and whatever bullshit. end) end And now you can call that function everytime you want to put money on the table. So for instance, you go into your table entity and have this while money on the table is < than the max amount of money allowed on the table do now we put an if function in the while loop. *Side note for the explanation I am about to write.* Make it so that the colmuns are saved when they are made. For example, you have colmun 1 and money is stacking, when colmun 1 gets high enough, you start on colmun 2. You would have ent.colmun = 1 or 2 or whatever colmun it is on. So now the if function. (The current colmun x should be defined when it starts, so like the script starts running, and column x is defined as 1. Once it is done, it will be defined as column 2. Etc etc.) local function addcolumnnumber (num) ent.column = ent.column + num end if amountofbillsin colmun x > specified amount then addcolumnnumber(1) do the check again or add money. You can make this check and the add column check seprate functions and just have them run over and over again until it works. end end Not sure if you understand what I am saying but basically have a defined column number, check if they money can stack in that column(if the column has already reached maximum capcity in holding bills) and if it can then add a bill. If all the columns are taken then just have it wait. Maybe just make a whole timer for it that never stops and keeps checking. I dunno, I feel like I got more and more incoherent but if you understood it then great, if you didn't then I dunno what to tell you.[/QUOTE] I think I get your draft, although 'l[lua]' tags would be relevant.
Sorry, you need to Log In to post a reply to this thread.