Randoms
#1

pawn Код:
new decide = random(2);
        if(decide == 0);
        {
            return EVENT_TEAM_RED;
        }
        if(decide == 1);
        {
            return EVENT_TEAM_BLUE;
        }
This returns two errors

if(decide == 0); << error:Empty Statement
if(decide == 1); << error:Empty Statement

Why?
Reply
#2

The semicolon at the end of the if statement must be removed.
Reply
#3

Try this
pawn Код:
// Your_Callback()
{
    // Code(Optional. If you have)
    new
        decide = random(2);
    switch(decide) {
        case 0: {
            return EVENT_TEAM_RED;
        }
        case 1: {
            return EVENT_TEAM_BLUE;
        }
    }
    // Rest
    return 1;
}
Reply
#4

Quote:
Originally Posted by Kostas'
Посмотреть сообщение
Try this
pawn Код:
// Your_Callback()
{
    // Code(Optional. If you have)
    new
        decide = random(2);
    switch(decide) {
        case 0: {
            return EVENT_TEAM_RED;
        }
        case 1: {
            return EVENT_TEAM_BLUE;
        }
    }
    // Rest
    return 1;
}
Take a look at code optimization. You have a singular type statement yet you group it as a compound statement.
Reply
#5

OH MY GOD LOL THE SEMICOLONS
Reply
#6

Quote:
Originally Posted by Rob_Maate
Посмотреть сообщение
OH MY GOD LOL THE SEMICOLONS
go away troll.
Reply
#7

Quote:
Originally Posted by titanak
Посмотреть сообщение
go away troll.
How the fuck am I a troll you e-warrior.
I was just amazed that I missed the semicolon
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
That's not inefficient code - it compiles to EXACTLY the same thing as if the braces had been ommitted, and is (IMHO) much clearer to read than something all squashed together (as you wrote).
Have I mentioned it was inefficient? My reference towards code optimizations was only meant to state if/when executing a singular statement or function it may be called after the preceding instruction. I have not stated that this is the ideal way of grouping single statements but a minor note.

pawn Код:
it compiles to EXACTLY the same thing as if the braces had been ommitted, and is (IMHO) much clearer to read than something all squashed together (as you wrote).
It is not squished together, and as a programmer, I'm hoping you understand that actually IS easier and much clearer to read. An example from my tutorial.

pawn Код:
#define while2(%0=%1;%2) %0=%1; while(%2)
main()
{
    while2(new i=100; i--)
    {
        printf("%d",i);
    }
}

pawn Код:
#define while2(%0=%1;%2) %0=%1; while(%2)
main()
{
    while2(new i=100; i--) printf("%d",i);
}
Reply
#9

In sort, what he means(at least i think) is to make it like that.
pawn Код:
new
    decide = random(2);
    switch(decide) {
            case 0: return EVENT_TEAM_RED;
            case 1: return EVENT_TEAM_BLUE;
    }
By the way i always prefer to have the brackets in the same place(both opening and closing) and if it's just a value, same line with the "new", but this is just how i like it. Your choice!

pawn Код:
new decide = random(2);
switch(decide)
{
        case 0: return EVENT_TEAM_RED;
        case 1: return EVENT_TEAM_BLUE;
}
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
I'm not sure what you mean by that.
I've referenced him to look at some code optimizations. In particular, after an instruction given, follows a statement or function. Braces aren't required nor without braces are not ideal when a single statement follows that same instruction.

Quote:
Originally Posted by ******
That is the code I was referring to as "squashed".
You say the second is more 'clarified' than the first?

pawn Код:
new decide = random(2);
if(decide == 0) return EVENT_TEAM_RED;
else if(decide == 1) return EVENT_TEAM_BLUE;
pawn Код:
new decide = random(2);
if(decide == 0)
{
    return EVENT_TEAM_RED;
}
else if(decide == 1)
{
    return EVENT_TEAM_BLUE;
}
Quote:
Originally Posted by ******
If you are arguing that grouping single statements as compound statements is easier to read (as your posts seem to indicate, though I'm not too clear on what you're trying to say) then I really do disagree, but you're free to do it that way - I was just pointing out that it's not a code optimisation issue, just a layout issue.
*If I've understood your post correctly, then no this is NOT what I have been saying at all. Grouping single statements without braces (which would NOT be a compound statement) is what I have been saying. You are also free to disagree, but you state that the second example provided (which is my assumption) is more understandable than the first which I must also disagree.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)