AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Couple of questions pertaining to small (https://forums.alliedmods.net/showthread.php?t=1711)

Ronkkrop 05-05-2004 19:51

Couple of questions pertaining to small
 
I have a couple of questions pertaining to small, or at least the implementation of small for amx x.

1. looping? for///while, and how?
2. if statement, how?
3. is it possible to write a config file?
4. is it possible to get a steamid?

AssKicR 05-05-2004 20:00

1
Code:
for ( new aa=1; aa<=32; aa++ ) {    server_print("aa == %i",aa) }

Code:
new aa=1 new bb=100 while (aa < bb) {    bb += 1    server_print("aa == %i / bb == %i",aa,bb) }

2
Code:
if (aa == bb) {    server_print("aa == bb") } else if (aa > bb) {    server_print("aa > bb") } else if (aa < bb) {    server_print("aa < bb") } else {    server_print("aa != bb") }

to avoid using many IF/ELSE switches u can use a SWITCH/CASE
Code:
new aa = random_num(1,5) switch (aa) {    case 1:server_print("aa = 1")    case 2:server_print("aa = 2")    case 3:    {       server_print("aa = 3")       server_print("OMG MAGIC NUMBER 3!!!")    }    case 4:server_print("aa = 4")    case 5:server_print("aa = 5") }

3.
Code:
stock LoadConfig() {     if(file_exists("addons/amxx/FileToLoad.ini") == 1) {         new line, stxtsize         new data[192]         while((line=read_file("addons/amxx/FileToLoad.ini",line,data,191,stxtsize))!=0)         {             if ( data[0] == ';' ) continue             if (equal("SomeValue",data)) {                 //DO STUFF!!!!             }         }     }else{         server_cmd("echo [AMXX] 404 Error!!! File Not Found!!!")         log_amx("[AMXX] 404 Error!!! File Not Found!!!")     } }

4
Code:
new SteamId[33] get_user_authid(id,SteamId,32) server_print("%i has Steamid %s",id,SteamId)

Nick 05-05-2004 20:01

Join any server and type status in console You'll see your steam id

AssKicR 05-05-2004 20:02

Quote:

Originally Posted by Nick
Join any server and type status in console You'll see your steam id

this is coding questionsidiot!!!

Ronkkrop 05-05-2004 20:05

Thanks for tellin me.

anybody wanna clear up file io, that would be great, mmmmk?

edit: oh, and you have a code issue with your while loop. That beast would go forever should be aa+=1

AssKicR 05-05-2004 20:08

Moooooved Up

FlyingMongoose 05-05-2004 20:08

cases are possible as well, if you don't want to do multiple if statements

AssKicR 05-05-2004 20:10

Moooved Up

Ronkkrop 05-05-2004 20:11

AssKicR, you are teh shi....

thanks man, you rock

FlyingMongoose 05-05-2004 20:14

I was just about to edit my post for that, though you forgot to include an example of a multiple line case statement :P

Code:
new aa = random_num(1,5) switch (aa) {    case 1: {               server_print("aa = 1")               server_print("aa = 1[2]")            }    case 2:server_print("aa = 2")    case 3:server_print("aa = 3")    case 4:server_print("aa = 4")    case 5:server_print("aa = 5") }

Ronkkrop 05-05-2004 20:17

yeah, thanks for tryin to clear that up with the multiple line case statement, but it doesn't overly matter for me at least.

I know a pile of languages, pickin up small seems like a piece of cake. I just needed to see a couple examples of syntax.

AssKicR 05-05-2004 20:19

the

Quote:

IF/ELSE
DO/WHILE
FOR
SELECT(SWITCH)/CASE
are kinda like global rules... They are in all scripting languages... Some with minor modifications.. Ur exaples of syntax are in my first post :D

Ronkkrop 05-05-2004 20:20

the comment wasn't for you AssKicR, it was for mongoose, i was trying to say i already understand

AssKicR 05-05-2004 20:21

ye i figured that, but i used the opertunity to shoot out some more facts :D

FlyingMongoose 05-05-2004 20:22

yeah ;) I got that, lol, small is a simple scripting language to learn, considering my knowledge lies majoritively in C++, VB, and BASIC, I picked up small pretty quickly.
I think asskicr's trying to avoid his head exploding by retaining too much info...gives you a headache sometimes, lol, just letting it seep out

AssKicR 05-05-2004 20:23

Quote:

Originally Posted by FlyingMongoose
...blahblahblah...

also scripting is pretty logical so it is simple :D

Ronkkrop 05-05-2004 20:27

This is a pretty good starting point for noobies. It should really be stickied, no?

AssKicR 05-05-2004 20:28

dunno :? , not my call anyways

Ronkkrop 05-05-2004 20:29

well i assumed that it wasn't...but perhaps a new post should be made by a mod with these simple tips and then stickied

AssKicR 05-05-2004 20:30

There will prolly be something like em in the Scripting Tutorial that gets released with "Amxx 0.20"

QwertyAccess 05-05-2004 21:32

maybe 8)


All times are GMT -4. The time now is 22:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.