Function error: "Arithmetic operation resulted in an overflow."

Is it possible that Quest has a limit for the number of functions in one line?

Let me explain trough code:

http://pastebin.com/c8aAJA7G

Now that is all displayed in SINGLE msg script.

The problem lies in the MapTiles()

I have tried to change the " + MapTiles() + " into TEST or anything that isn´t a function and it works well.
I am 99% sure the problem isn´t the function itself because I have set it to return a simple number "2" and it still doesn´t work.

(Even if I set it to string or anything simple, it still throws an error, so I hope the issue isn´t the function)

I always get this error: "Arithmetic operation resulted in an overflow."


Oh, your the one that did the "ship mover" thingy!!!
I worked out an easer way to "move" the ship...
SetCounter ("Position", GetInt(game, "Y") * 20 + GetInt(game, "X"))
And maybe simpler:
Position= Y * 20 + X
One line replaces all your IF statements...

In Basic, MapTiles() is a matrix variable and is used with an index number...
X=MapTiles(player.Position)
To select which value you want...
I did not know Quest had something similar!

Quest maybe trying to identify MapTiles() as a function...


or... could it be:
{if player.Position=383:÷}{if player.Position<>383:" + MapTiles() + "}
Drop the "+" signs?


"I worked out an easer way to "move" the ship..."
Well, I have already learned how to use functions and I have reduced the amount of code by 90% so that´s working.

(This is what happens when you are too arrogant to read the useful Quest documentation, lol)

"In Basic, MapTiles() is a matrix variable..."

Well I just changed the function to have a different name and it still doesn´t work... so I am not sure if that´s the case.

PS: Also, I can´t drop the + sings because they simply have to be there for Quest to recognize them.
I tried misspelling the function name to something and Quest immediately recognized that, so for sure, it KNOWS what to do but the problem is that something goes wrong when it does that.


Glad you got that figured out... learning the code helps...

Yes... it was a bad guess...
I did play with your change but for me it just printed the text: MapTiles()
in place of the grid character .

Try this, go back to the grid character, and just work with MapTiles() in one place
and experiment to get that one space to work.

What does your function MapTiles() look like?
I may be able to help there... (maybe)


You have probably inserted MapTiles() within the "" of the msg script, Quest then interprets it like plain text.
If you are doing it trough GUI, set print to EXPRESSION instead of MESSAGE.

The function is currently just a placeholder, currently it is supposed to return an integer value of 2. That´s all.

The function is supposed to make it easier for map tiles to be changed, currently you have to slug trough very massive msg command and it is VERY unclear which part does what so it´s a mess.

I want my "experiment" to be more readable by anyone who is willing to do something like me so I need to make it more elegant.

If I made a function that could easily just put a different character for each "tile" anyone could just adjust the map to display anything he wants, without hours of frustrating headaches.

But I will figure it out, somehow...


Might be easier in two loops. Something like...

s = "┌──────────────────────────────────────────────┐<br/>"
for (row, 20, 1, -1){
  s = s + ":|"
  for (col, 1, 20) {
    if (player.Position = row * 20 + col) {
      s = s + "÷"
    }
    else {
      s = s + MapTiles()
    }
  }
  s = s + "<br/>"
}
s = s + " └─────────────────────────────────────────────┘"  
msg(s)

I "knew" a loop could be done!!!
I just didn't know how... thanks!

Pixie:
But what about the MapTile() problem?
Does Quest have a array variable?
IE:
M(1)="Test"
M(2)="This"
M(3)="OOPS!"
Then:
msg(M(1))
would show (print):
Test
???


@ DarkLizard:

loops/iterations/recursion:

  1. 'while' Function
  2. 'for' Function
  3. 'foreach' Function
  4. calling/'do' Function/'invoking' Function, the parent Function/Script_Attribute from within the parent Function/Script_Attribute 's scripting:
// this is NOT terminated (endless/infinite loop), but it's just an example of calling a Function (via tail-recursion):
<function name="hi_function">
  msg ("hi")
  hi_function
</function>

Script Attributes:

// this is NOT terminated (endless/infinite loop), but it's just an example of calling a Script Attribute (via tail-recursion):

<game name="xxx">
  <attr name="start" type="script">
    msg ("hi")
    invoke (game.start)
  </attr>
</game>

// or:

<game name="xxx">
  <attr name="start" type="script">
    msg ("hi")
    do (game, "start") // 'do' is more powerful/useful than the 'invoke' Function, as (one reason of a few) you can concatenate with it, unlike within 'invoke' Function
  </attr>
</game>

'arrays' are known as 'Lists (String List Attributes and Object List Attributes)' in quest:

http://docs.textadventures.co.uk/quest/guides/using_lists.html
http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk


What you could do is create an HTML table, with each cell of thrtable corresponding to a square on your map, and colour the background as required (which is what did in Deeper). You could then use a string dictionary to hold the landscape data, and have the player as an image on top of that.

Here is an example where the map is ocean with an island, and the player can move around the water tiles. Works best if you have an image, ship.png, in the same folder.

<!--Saved by Quest 5.6.6108.15891-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="map">
    <gameid>a3d22ef7-2aa1-48e8-a6cb-64430375744e</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <start type="script">
      player.row = 2
      player.col = 3
      game.landscape = NewStringDictionary()
      MapBox (8, 11, 11, 14, "PaleGreen")
      MapBox (11, 12, 13, 16, "PaleGreen")
      MapSet (9, 15, "SpringGreen")
      MapSet (10, 15, "SpringGreen")
      MapSet (10, 16, "SpringGreen")
      MapBox (12, 13, 14, 15, "Silver")
      MapSet (11, 13, "Silver")
      MapSet (13, 14, "White")
      Map
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <exit alias="west" to="room">
        <inherit name="westdirection" />
      </exit>
    </object>
    <exit alias="east" to="room">
      <inherit name="eastdirection" />
      <runscript />
      <script type="script">
        Move (1, 0)
      </script>
    </exit>
    <exit alias="north" to="room">
      <inherit name="northdirection" />
      <runscript />
      <script type="script">
        Move (0, 1)
      </script>
    </exit>
    <exit alias="south" to="room">
      <inherit name="southdirection" />
      <runscript />
      <script type="script">
        Move (0, -1)
      </script>
    </exit>
    <exit alias="west" to="room">
      <inherit name="westdirection" />
      <runscript />
      <script type="script">
        Move (-1, 0)
      </script>
    </exit>
  </object>
  <function name="Map"><![CDATA[
    s = "<table style=\"border-spacing:0;border-collapse:collapse;\">"
    for (row, 20, 1, -1) {
      s = s + "<tr>"
      for (col, 1, 20) {
        key = MapKey(col, row)
        if (player.row = row and player.col = col) {
          content = "<img src=\"" + GetFileURL("ship.png") + "\"/>"
        }
        else {
          content = "&nbsp;&nbsp;&nbsp;&nbsp;"
        }
        if (DictionaryContains(game.landscape, key)) {
          s = s + "<td style=\"background: " + StringDictionaryItem(game.landscape, key) + ";\">" + content + "</td>"
        }
        else {
          s = s + "<td style=\"background: LightBlue;\">" + content + "</td>"
        }
      }
      s = s + "</tr>"
    }
    msg (s + "</table>")
  ]]></function>
  <function name="MapKey" parameters="col, row" type="string"><![CDATA[
    return (">" + row + "," + col + "<")
  ]]></function>
  <function name="MapSet" parameters="col, row, colour">
    key = MapKey(col, row)
    if (DictionaryContains(game.landscape, key)) {
      dictionary remove (game.landscape, key)
    }
    dictionary add (game.landscape, key, colour)
  </function>
  <function name="MapBox" parameters="col1, row1, col2, row2, colour">
    for (row, row1, row2) {
      for (col, col1, col2) {
        MapSet (col, row, colour)
      }
    }
  </function>
  <function name="Move" parameters="col, row"><![CDATA[
    new_col = player.col + col
    new_row = player.row + row
    if (new_col > 20 or new_col < 1 or new_row > 20 or new_row < 1) {
      msg ("Edge of the world")
    }
    else if (DictionaryContains(game.landscape, MapKey(new_col, new_row))) {
      msg ("Land")
    }
    else {
      player.col = new_col
      player.row = new_row
      Map
    }
  ]]></function>
</asl>

What dimensions for Ship.png?


Cool, a graphic programming in a "text" only environment!
Anyway to stop the new picture from scrolling up?
ClearScreen does not work.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums