script_parse_error (curtoken, "Expected a ')' at the end of a condition block");
return NULL;
}
- curtoken = ply_scan_get_next_token(scan);
+ ply_scan_get_next_token(scan);
script_op* cond_op = script_parse_op(scan);
script_op* else_op = NULL;
if (type == SCRIPT_OP_TYPE_IF &&
curtoken->type == PLY_SCAN_TOKEN_TYPE_IDENTIFIER &&
!strcmp(curtoken->data.string, "else")){
- curtoken = ply_scan_get_next_token(scan);
+ ply_scan_get_next_token(scan);
else_op = script_parse_op(scan);
}
}
+static script_op* script_parse_for (ply_scan_t* scan)
+{
+ ply_scan_token_t* curtoken = ply_scan_get_current_token(scan);
+ if (curtoken->type != PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
+ return NULL;
+ if (strcmp(curtoken->data.string, "for")) return NULL;
+
+ curtoken = ply_scan_get_next_token(scan);
+ if (curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL || curtoken->data.symbol != '('){
+ script_parse_error (curtoken, "Expected a '(' at the start of a condition block");
+ return NULL;
+ }
+ curtoken = ply_scan_get_next_token(scan);
+
+ script_exp* first = script_parse_exp (scan);
+ if (!first){
+ script_parse_error (curtoken, "Expected a valid first expression");
+ return NULL;
+ }
+
+ curtoken = ply_scan_get_current_token(scan);
+ if (curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL || curtoken->data.symbol != ';'){
+ script_parse_error (curtoken, "Expected a ';' after the first 'for' expression");
+ return NULL;
+ }
+ ply_scan_get_next_token(scan);
+
+ script_exp* cond = script_parse_exp (scan);
+ if (!cond){
+ script_parse_error (curtoken, "Expected a valid condition expression");
+ return NULL;
+ }
+
+ curtoken = ply_scan_get_current_token(scan);
+ if (curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL || curtoken->data.symbol != ';'){
+ script_parse_error (curtoken, "Expected a ';' after the 'for' condition");
+ return NULL;
+ }
+ ply_scan_get_next_token(scan);
+
+ script_exp* last = script_parse_exp (scan);
+ if (!last){
+ script_parse_error (curtoken, "Expected a valid last expression");
+ return NULL;
+ }
+
+ curtoken = ply_scan_get_current_token(scan);
+ if (curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL || curtoken->data.symbol != ')'){
+ script_parse_error (curtoken, "Expected a ')' at the end of a for block");
+ return NULL;
+ }
+ ply_scan_get_next_token(scan);
+ script_op* op_body = script_parse_op(scan);
+
+
+ script_op* op_first = malloc(sizeof(script_op));
+ op_first->type = SCRIPT_OP_TYPE_EXPRESSION;
+ op_first->data.exp = first;
+
+ script_op* op_last = malloc(sizeof(script_op));
+ op_last->type = SCRIPT_OP_TYPE_EXPRESSION;
+ op_last->data.exp = last;
+
+ script_op* op_for = malloc(sizeof(script_op));
+ op_for->type = SCRIPT_OP_TYPE_FOR;
+ op_for->data.cond_op.cond = cond;
+ op_for->data.cond_op.op1 = op_body;
+ op_for->data.cond_op.op2 = op_last;
+
+
+ script_op* op_block = malloc(sizeof(script_op));
+ op_block->type = SCRIPT_OP_TYPE_OP_BLOCK;
+ op_block->data.list = ply_list_new();
+ ply_list_append_data(op_block->data.list, op_first);
+ ply_list_append_data(op_block->data.list, op_for);
+
+ return op_block;
+}
+
+
+
reply = script_parse_if_while (scan);
if (reply) return reply;
+ reply = script_parse_for (scan);
+ if (reply) return reply;
+
reply = script_parse_return (scan);
if (reply) return reply;
}
case SCRIPT_OP_TYPE_IF:
case SCRIPT_OP_TYPE_WHILE:
+ case SCRIPT_OP_TYPE_FOR:
{
script_parse_exp_free (op->data.cond_op.cond);
script_parse_op_free (op->data.cond_op.op1);
SpriteSetY (logo.sprite, 300 - ImageGetHeight(logo.image));
SpriteSetOpacity (logo.sprite, 1);
}
- if (status != "normal"){
+ else{
SpriteSetOpacity (throbber_sprite, 0);
SpriteSetX (logo.sprite, 0);
SpriteSetY (logo.sprite, 0);
SpriteSetOpacity (lock.sprite, opacity);
SpriteSetOpacity (entry.sprite, opacity);
index = 0;
- while (bullet[index]){
+ for (index = 0; bullet[index]; index++){
SpriteSetOpacity(bullet[index].sprite, opacity);
- index++;
}
}
global.status = "password";
if (!global.dialogue) dialogue_setup();
dialogue_opacity (1);
- index = 0;
- while (dialogue.bullet[index] || index < bullets){
+ for (index = 0; dialogue.bullet[index] || index < bullets; index++){
if (!dialogue.bullet[index]){
dialogue.bullet[index].sprite = SpriteNew();
SpriteSetImage(dialogue.bullet[index].sprite, dialogue.bullet_image);
if (index < bullets){
SpriteSetOpacity(dialogue.bullet[index].sprite, 1);
}
-
- index++;
}
}
PlymouthSetDisplayPasswordFunction(display_password);