File: dictionary.ss

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (48 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// dictionary.ss
// How to use the Dictionary in SurgeScript
// Copyright 2017-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
//

object "Application"
{
    // a Dictionary is a set of (key, value) pairs
    weight = {
        "Surge": 35,
        "Neon": 20,
        "Charge": 37.5,
        "Gimacian": 70
    };
    
    // main state
    state "main"
    {
        // change some weights ("weight" as in everyday use, that is)
        weight["Neon"] = 25;
        weight["Charge"] += 3;

        // print the weights
        Console.print("Surge weighs " + weight["Surge"] + " kg.");
        Console.print("Neon weighs " + weight["Neon"] + " kg.");
        Console.print("Charge weighs " + weight["Charge"] + " kg.");
        Console.print("Gimacian weighs " + weight["Gimacian"] + " kg.");

        // sum up
        totalWeight = computeTotalWeight();
        Console.print("Together, they weigh a total of " + totalWeight + " kg.");

        // done!
        Application.exit();
    }

    // this function will add all weights stored in the Dictionary.
    fun computeTotalWeight()
    {
        sum = 0;

        foreach(entry in weight)
            sum += entry.value;

        return sum;
    }
}