From fcd30be44982cfe79ed777b19b2543fe3e72e239 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Jan 2012 00:37:48 -0700 Subject: +=, -=, *=, /= works with indexed dicts/lists --- bloodfields.stage | 27 ++++++++------------------- src/parser.y | 4 ++++ test.stage | 8 +++----- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/bloodfields.stage b/bloodfields.stage index 91bee08..58a24a2 100644 --- a/bloodfields.stage +++ b/bloodfields.stage @@ -78,21 +78,15 @@ function status() function look() { + display('''You are standing in a field of wheat.'''); if exists(global.enemy) then { - display('''You are standing in a field of wheat. You see a ''' + - global.enemy['name'] + ''' in front of you.'''); + display('You see a ' + global.enemy['name'] + ' in front of you.'); } else if exists( global.treasure ) then { - display('''You are standing in a field of wheat. You find a ''' + - global.treasure['name'] + ''' lying here!'''); + display('You find a ' + global.treasure['name'] + ' lying here!'); } - else - { - display('''You are standing in a field of wheat.'''); - } -// status(); } function mkEnemy() @@ -107,9 +101,8 @@ function mkEnemy() } global.enemy['name'] = global.enemyMods[mod]['name'] + ' ' + global.enemy['name']; - global.enemy['attack'] = global.enemy['attack'] + - global.enemyMods[mod]['attack']; - global.enemy['hp'] = global.enemy['hp'] + global.enemyMods[mod]['hp']; + global.enemy['attack'] += global.enemyMods[mod]['attack']; + global.enemy['hp'] += global.enemyMods[mod]['hp']; global.enemy['level'] = mod; } @@ -137,7 +130,7 @@ function playerAttack() display('You killed the ' + global.enemy['name'] + '! You gained ' + xp + ' experience points.'); player.xp += xp; - if player.xp >= 100 then + while player.xp >= 100 do { player.xp -= 100; player.level += 1; @@ -176,16 +169,12 @@ function enemyAttack() situation <> { - command: "hi" - { - display("Yup, you're in travel."); - } - enter { delete( global.enemy ); + delete( global.treasure ); - display('You wander aimlessly through the seemingly endless field of wheat.'); + display('You wander aimlessly through the endless field of wheat.'); select = random(1,6); if select <= 4 then // 66% of the time, enemy! diff --git a/src/parser.y b/src/parser.y index 2e9eead..2aff29c 100644 --- a/src/parser.y +++ b/src/parser.y @@ -245,6 +245,10 @@ expr: literal | expr tokGtEq expr { bld.addNode( AstNode::tCompGtEq ); } | '(' expr ')' | expr '[' expr ']' { bld.addNode( AstNode::tIndex ); } + | expr '[' expr ']' tokPlusAssign { bld.addNode( AstNode::tIndex ); } expr { bld.addNode( AstNode::tPlusStore ); } + | expr '[' expr ']' tokMinusAssign { bld.addNode( AstNode::tIndex ); } expr { bld.addNode( AstNode::tMinusStore ); } + | expr '[' expr ']' tokTimesAssign { bld.addNode( AstNode::tIndex ); } expr { bld.addNode( AstNode::tMultiplyStore ); } + | expr '[' expr ']' tokDivideAssign { bld.addNode( AstNode::tIndex ); } expr { bld.addNode( AstNode::tDivideStore ); } | expr '[' expr ']' '=' expr { bld.addNode( AstNode::tInsert ); } | '[' ']' { bld.addLiteral( Variable( Variable::tList ) ); } | '[' { bld.addLiteral( Variable( Variable::tList ) ); } listValues ']' diff --git a/test.stage b/test.stage index 4ffec79..42529af 100644 --- a/test.stage +++ b/test.stage @@ -17,11 +17,9 @@ situation <> { setup { - for each i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] do - { - display( random(0.25, 0.5)*10 ); - } - display( 0.25 * 10.0 ); + global.stuff = {'count': 1}; + global.stuff['count'] += 5; + display( global.stuff['count'] ); exit(); } -- cgit v1.2.3