Tech Lounge > Programming

Learning Simple E2 with Kräsher!

<< < (7/8) > >>

Peetah:
gets pretty complicated once you get to the animating the bones part. use a timer.

Krasher:
ArraysLets do some simpler arrays, maybe one that prints every players name in the server :D.
Full Code:
--- Code: ---@name Array Test
@persist [Array Players]:array Total

runOnChat(1)

LastS=owner():lastSaid():lower()

Total=findByClass("player")
Players=findToArray()

for(I=1,Players:count()){
    Array[I,string]=Players[I,entity]:name()

if(LastS=="/run"){
for(K=1, Array:count()){
    print(Array[K,string])
        }
    }
}

--- End code ---
Explanation:runOnChat(1) makes the e2 trigger-able by the chat.
LastS=owner():lastSaid():lower(), this is a variable I made that will make life easier.
findByClass("player") is the part where we find all the players.
findToArray() is the part where we put it into an array. I put mine into a variable. (Players)
for(I=1, Player:count()) this function (for) lets me set up my arrays. I (or 1) is our index, Player:count() is the number of players. So it is basically for(1 to 4) (Implying we have 4 people in the server.)
Array[I,string] tell the e2 that our array 1 (I) will be a string. (Basically saying: Array 1 (or I) is a string)
Players[I,entity]:name() Players will be put into an array. The array tells the e2 that we will classify "Players" as an entity. name() Will get the name of the players.
LastS=="/run" ''=='' means 'Is equal to", Basically this line means, If the players last said is /run.
for(K=1, Array:count()) using K as an index this time, then we just count the number of arrays in our previous index. (Amount of players)
print(Array[K,string]) telling the e2 to print the Array (Index) of K as a string.

If you need further help on Arrays, it is best if you steam message me, PM me, or ask me in-game. Arrays can be hard to understand at first, but they are super easy :P.

SheepsAholy:
Krasher I'd rather do this:


--- Code: ---@name Array Test
@persist Players:array

runOnChat(1)
LS = owner():lastSaid():explode(" ")
Clk = chatClk(owner())

if(Clk & LS:string(1) == "/r")
{
findByClass("player")
Players = findToArray()
}

if(Clk & LS:string(1) == "/i")
{
print(Players[LS:string(2):toNumber(),entity]:name())
}
--- End code ---

Players:array will hold all the players the chip finds in the "/r" if-statement (the first if line.)
If you type /r again all the indexes of the old will be replaced with the new find values.

LS = owner():lastSaid():explode(" ")
this is similar to krashers but instead of :lower() its :explode(" ") which turns it into an array.

This array makes an index for each space you type and the value for that index is anything but a space. Example:

this is a test.

Index|Value
1: this
2: is
3: a
4: test.

Clk = chatClk(owner())
You don't have to use this, I do in all my chat cmd e2's just because I believe its good coding practice.

Similar to above, when you have used the /r cmd it will make the Players:array equal to what it finds. And when you type /i <value> it will print what it finds at that index. Example again:

Index | Name
1. Bob
2. Joe
3. Dirt

/i 1 = Bob
/i 2 = Joe
/i 3 = Dirt

Any value under 1 and any value over 3 will still run the chip and print a "space"

also if you do something like below:

/i tom

it will also run the chip but will not be of much help.

but the way the /r is coded, it will run even if you do this:

/r tom

I'm not much of the explainer online meet me ingame and I'm more of a help ;)

P.s sry about stealing you thread krasher :P

Krasher:
its k

Arrays are hard to explain online in text
lol xP

SheepsAholy:
its 3 a.m. in the morning I'm to sleepy to explain anything accurate online. Had to type that stuff above 3 times and even edit that once to get it decent lol.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version