Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

variables

A topic by Bastian created Jun 10, 2020 Views: 143 Replies: 4
Viewing posts 1 to 4

Hello, looking for some unusual puzzle mechanics in a game that i am trying to create. It works around variables and the way how they can be accessed. I am currious if  the engine allows something like this:

If i have a variables like this -> s1 : string "1234"; s2 : string "0204"; idx : integer "2"; str : string "";

I know the idx variable has number value 2 this means i would like to get content of s2. And then check if s2 contains character "3" in the string. If it contains character "3" the function would return true to me. In the game the idx changes when player interacts. And the result of change is stored as constant in those s1, s2.. variables. The content of the variable is like information for me what can be done at the moment in the game.

Example:

str = get_string_variable "s"+idx -> dynamically get the content of s2 string

if (str contains "3") then print "character 3 is included in string " + str;

Host

GOOD NEWS

Most of that is already in the realms of what Adventuron can do, I was planning on adding standard string functions in the (very) near future (str_len, str_indexof(), etc).

The rest of it is certainly possible.

BAD NEWS

This type of functionality will never be part of 8-bit compatibility mode.  DAAD (the 8-bit text adventure engine)does not support such features.

GOOD NEWS (?)

 The good news is the 8-bit compatibility mode is an optional requirement of the jam.

Submitted

I think I know what you're trying to do, but I think there are better ways to do it using states and boolean variables. Nevertheless, I saw this as a bit of a challenge, so let's see what I came up with...

First up, let me say that I don't think you can do what you're trying to do using strings because there are no (documented) string functions in Adventuron that allow you to extract substrings. However, you can do the same thing if you use an integer rather than a string. Each digit in the integer corresponds to a character in your strings s1, s2 and so on.

First of all, set up the placeholders for your integers. index is the index used to select which of the integers to use. s1, s2 & s3 are the integers. (Add more as needed.) number is which of those integers was selected. (This will be modified during the extraction process.) digit is the digit that you're looking for in number. temp is a temporary variable used during the extraction process.

integers {
   index : integer "2";
   s1 : integer "1234";
   s2 : integer "0204";
   s3 : integer "3579";
   number : integer "0";
   digit : integer "3";
   temp : integer "0";
}

Secondly, create a boolean to store the result. This will return true if the digit is in number and false if it is not in the number.

booleans {
   result : boolean "false";
}

Thirdly, we need a bit of code in your on_command {} section to set the index, integers s1, s2 & s3, and the digit that you want to test (not shown here, because I don't know how you want to set these up) and a call to the subroutine that will do the work.

on_command {
   : match "test me" {
      : gosub "contains_digit";
      : if (result) {
         : print "Contains digit.";
      }
      : else {
         : print "Does not contain digit.";
      }
      : done;
   }
}

Finally, we need a subroutine to do the grunt work.

subroutines {
   contains_digit : subroutine {
      : if (index == 1) {
         : set_integer var = "number" {(s1)}
      }
      : else_if (index == 2) {
         : set_integer var = "number" {(s2)}
      }
      : else {
         : set_integer var = "number" {(s3)}
      }
      : while (number != 0) {
         : set_integer var = "temp" {(number % 10)}
         : if (temp == digit) {
            : set_true "result";
            : return;
         }
         : set_integer var = "number" {(number / 10)}
      }
      : set_false "result";
      : return;
   }
}

I hope this does what you want. (And I'm pretty sure this is 8-bit compatible, though I haven't tried it.)

(+1)

Yes that is what i need to make the puzzle tick right. Thank you Garry.

Maybe a consideration for arrays in adventuron engine? Something that makes setting, getting and swapping values in an indexed array would come in handy.

puzzle : array = [1,5,8,9,1,2]

set_array (puzzle, index, value)

value = get_array(puzzle, index)

swap_array (puzzle, index1, index2)

Host

Adventuron does have arrays but I certainly don't have time to map them to the DAAD engine (which does not have arrays) in the duration of the jam. If not operating in 8-bit mode, I can elaborate on arrays a bit more later.