theRAPTLab / gsgo

GEM-STEP Foundation repo migrated from GitLab June 2023
1 stars 1 forks source link

Feature: `ifProp` and `ifFeatProp` - [merged] #711

Closed benloh closed 1 year ago

benloh commented 2 years ago

Merges dev-bl/if -> dev-next

Branch: dev-bl/if

This adds two new keywords: ifProp and ifFeatProp targeted at making it easier for students to construct if statements. ifExpr still works.

ifProp

ifProp lets you construct conditions taking advantage of built-in gvar prop methods. e.g.

  `ifProp Fish.energyLevel gt 0 [[ ... ]]`
  `ifProp Fish.name eq 'Wanda' [[ ... ]]`

ifFeatProp

Similarly, ifFeatProp accesses gvar prop methods for featProps. e.g.

 `ifFeatProp Fish.Movement.movementType eq 'stop' [[ ... ]]`
 `ifFeatProp Fish.Costume.scale lt 1 [[ ... ]]`

ifProp comparison to another prop

ifProp has a code-only feature that allows you to use another property as the argument for a prop method. e.g.

  `ifProp Fish.energyLevel gt Fish.threshold [[ ... ]]`

But there are a few caveats:

prop methods

Note that prop methods are strings, not symbol operators (e.g. gt, not >). The methods are actual javascript method names, so it is not easy to use symbols to replace them. That can potentially be a 2.0 feature.

The prop methods can be entered using the GUI, so it should be relatively easy to construct the if statements. And like other block commands, the consequent block will be added automatically when you create or edit the line.

benloh commented 2 years ago

requested review from @jdanish

benloh commented 2 years ago

added 1 commit

Compare with previous version

benloh commented 2 years ago

In GitLab by @moravick on Aug 29, 2022, 08:33

could we get a list of the working prop methods? i.e. eq, gt, etc?

benloh commented 2 years ago

@moravick there's two ways you can do this:

The easiest is actually to use the GUI: Do an addProp for each proptype (string, number, boolean), then do a prop xxx <method>. You'll see all the methods listed. Then do the same for each feature (e.g. featProp xxx <method>

The second easiest way is to code dive: search for class-sm-string, class-sm-number and class-sm-boolean. At the bottom of the file is a list of methods. Then search for feat-agentwidgets (etc.) and look for the list of methods at the bottom of the file.

benloh commented 2 years ago

added 1 commit

Compare with previous version

benloh commented 2 years ago

added 1 commit

Compare with previous version

benloh commented 2 years ago

In GitLab by @jdanish on Sep 3, 2022, 07:54

I think this can be merged in with help.

benloh commented 2 years ago

mentioned in commit ae3104b18445b6d3d78f899f637a035646f9909f

benloh commented 2 years ago

Merged with feature-help branch in !268