News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

Tutorial - code review

Started by Andarix, May 15, 2025, 01:22:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andarix

Quote from: Yona-TYT on May 15, 2025, 03:00:20 AMOk, I made the necessary changes to the "code_review" branch, and I also had to add another text file to step 7.

https://github.com/simutrans/tutorial_multipak/commit/5f75194943825323b5a53aba19e4cf5c80d5574c
https://github.com/simutrans/tutorial_multipak/commit/0aba71fec34e234ee67d943a0ec8e4d5a386819a



Additional note: The "cov_sw" flag that indicates whether the number of convoys in circulation is correct or not, seems to not be working in "code_review", as a result, when I delete the vehicle, the info in the scene window is no longer coherent.

        if (!cov_sw){
          text = ttextfile("chapter_02/07_3-4.txt")
          text.tx = ttext("<em>[3/4]</em>")

          local tile = my_tile(city2_halt_1[city2_halt_1.len()-1])
          text.stnam = ""+city2_halt_1.len()+") "+tile.get_halt().get_name()+" ("+coord_to_string(tile)+")"

          text.list = create_halt_list(city2_halt_1)
          text.nr = siz
        }




Are you sure it worked before?

cov_sw is initialized to true in scenario.nut.

It is evaluated once in Chapter 2. It is evaluated four times in Chapter 3.

A search of all files did not yield any further entries.

I haven't actually changed anything about that.

Yona-TYT

I need to review all of that. I'd also like to change the text labels to unowned, only in places where they can be used, of course.

@Andarix, I hope this doesn't hinder or harm your work. If so, please let me know, and I'll postpone this for another time.

@Prissi, I'm wondering if it's possible to use unowned text labels on player-owned roads/rails? If so, then I'll open an extension request.

Andarix

Quote from: Yona-TYT on May 16, 2025, 05:49:16 PM...
@Andarix, I hope this doesn't hinder or harm your work. If so, please let me know, and I'll postpone this for another time.
...

I've completed chapters 1 through 3 regarding the changes to the maps.

My tests with pak64 didn't cause any more errors. However, I only tested for correct functionality.

Yona-TYT

#3
There are several changes regarding moving "Follow Vehicle" to step 7: https://github.com/simutrans/tutorial_multipak/commit/0aba71fec34e234ee67d943a0ec8e4d5a386819a

cov_sw was actually a dead variable; the one that should be used in these cases is called correct_cov.
Fix here: https://github.com/simutrans/tutorial_multipak/commit/d6e0b8f54b3628a8eaae7f6cd6a4e0dab06a5cfe


Prissi did some cleanup on the "Schedule" code, and I've now moved her changes to the "code review" branch. Thanks a lot for your input @Prissi 8)
https://github.com/simutrans/tutorial_multipak/commit/73f960d1a577a2e22028388f2253964273989f7e


Edit.

You need to adjust the info in step 6 so that "text.list = create_schedule_list(city1_halt_2)" is used instead of "st1, st2 ...".

Screenshot 2025-05-21 at 12-02-42 .png

Andarix

chapter 5

I've revised the substations a bit and removed various tile definitions. However, the automatic tile search isn't complete yet.

I think we should be a bit more flexible with the post office extensions. Several sets also include post office stops. Therefore, I would rather allow both the extension with a post office building and the extension with a post stop.

The check has been changed so that the stop accepts mail.

Yona-TYT

Quote from: Andarix on May 27, 2025, 02:46:46 PMI think we should be a bit more flexible with the post office extensions. Several sets also include post office stops. Therefore, I would rather allow both the extension with a post office building and the extension with a post stop.


In fact, in pak192.comic's tutorial, the mechanics are a bit different, as it uses a combination of post buildings and post stops. I like the idea of combining both options . 8)

Andarix

Quote from: Yona-TYT on May 21, 2025, 03:38:59 PM...
Prissi did some cleanup on the "Schedule" code, and I've now moved her changes to the "code review" branch. Thanks a lot for your input @Prissi 8)
https://github.com/simutrans/tutorial_multipak/commit/73f960d1a577a2e22028388f2253964273989f7e
...

I think these changes aren't working correctly.

I can no longer create timetables.

However, it works in the release version of the tutorial.

Yona-TYT

Quote from: Andarix on May 27, 2025, 10:40:39 PMI think these changes aren't working correctly.

I can no longer create timetables.

However, it works in the release version of the tutorial.
I tried the first bus and it seems to work fine, where exactly is it failing?.

Andarix

#8
When I buy a vehicle from the depot, the vehicle isn't displayed at the top.

If I switch to the vehicle at the top, I can't access a new route. The timetable window doesn't open, and the field jumps back.

It's time for others to test the new code. Unpack the zip file to [pakset]/scenario and then select "Load Scenario".

errors

Chapter 2 step 4 texts are not correct because this was not changed on the translation page.
[edit]
chapter 2 step 6 1/2 text error halt list


[edit]
delete attaches files

new files here

Andarix

Quote from: Yona-TYT on May 27, 2025, 10:58:54 PMI tried the first bus and it seems to work fine, where exactly is it failing?.

It's possible that all the testing has caused some confusion.

Andarix

#10
bugfix version


[edit]

reupload files

Yona-TYT

It seems that this is a bad character, and there may be translation errors because of this.IMG_20250529_084944_251.jpg

Andarix

Quote from: Yona-TYT on May 29, 2025, 12:51:44 PMIt seems that this is a bad character, and there may be translation errors because of this.
...

Then take a look at Simutrans's es.tab.

Simutrans uses this symbol to mark UTF-8 translation files.

Andarix

Quote from: Andarix on May 28, 2025, 07:02:49 AM...
It's time for others to test the new code. Unpack the zip file to [pakset]/scenario and then select "Load Scenario".
....


no feedback = no bugs

 :)

Yona-TYT

Quote from: Andarix on June 07, 2025, 08:38:15 AMno feedback = no bugs

 :)
I haven't had much time to test, I'm afraid 😞

Isaac Eiland-Hall

Quote from: Andarix on June 07, 2025, 08:38:15 AMno feedback = no bugs

 :)

Soooo, if we shut down the forum, no more bugs! :hunts around for the delete command: ;-)

Yona-TYT

Quote from: Andarix on May 28, 2025, 03:17:47 PMIt's possible that all the testing has caused some confusion.
I guess everything's fine here, right?.



I've started changing the label texts to unowned, so far only "class_basic_chapter.nut" has been modified, let me know if you don't have any pending changes so I can proceed with changing this in the chapters.

https://github.com/simutrans/tutorial_multipak/commit/9fe7e541ade4d1ed1c5a0e10932f4d3337e11c65

Andarix

I have no changes at the moment.


Therefore my call to test, so that errors made by me are found.


Andarix

#19
The problem is the rotation of the map.


factory_data determines the coordinates at the start of the scenario and is therefore only valid in this orientation.

The factories are also indicated in this orientation.
/**
 *  set tiles for factory
 *
 *  coord_fac_1 - ch1, ch4
 *
 *
 */
coord_fac_1 <- coord(123,160) // Timber plantation
coord_fac_2 <- coord(93,153)  // Saw mill
coord_fac_3 <- coord(110,190) // Construction Wholesaler
coord_fac_4 <- coord(168,189) // Oil rig
coord_fac_5 <- coord(149,200) // Oil refinery
coord_fac_6 <- coord(112,192) // Gas station
coord_fac_7 <- coord(131,235) // Coal mine
coord_fac_8 <- coord(130,207) // Coal power station

In this case, an entry would have to be made in all 4 map orientations in order to take the appropriate one for the determined orientation of the map.


Otherwise the error lies with Simutrans or the script environment, because the changes to the map rotation are not applied correctly.

prissi

Theoretically, the script engine rotates internal coordinates following the rotation. Thus, the same coordinates should apply to rotated maps. It may be that this is lost when reloading.

Yona-TYT

Quote from: prissi on June 23, 2025, 01:00:07 PMThus, the same coordinates should apply to rotated maps. It may be that this is lost when reloading.
That may be because I did rotate the map at the beginning of the tutorial.

Andarix

#22
The problem may lie in the sequence.

The function rename_factory_names() is executed very early and accesses the coords of the factories (coord_fac_1 ....). And these coords are only specified for the start rotation.

This means that the map would have to be rotated to the appropriate rotation when saving and then back to the rotation that was displayed when saving after loading.

Alternatively, the coords of the factories (coord_fac_1 ...) would have to be overwritten and saved.

[EDIT]

I may have a solution.

Yona-TYT

Just like there is a "start_game()" function, maybe a function that is called every time a save is made could help?, although I don't know if this already exists (I don't think so).

prissi

Since the map rotation is saved, and the coordinates in the script are rotated according to this, the only way to mess this up, is when the rotation indicator is manipulated or there is an error in the program.

So how to reproduce the error?

Andarix

Quote from: Yona-TYT on Today at 11:25:56 AMJust like there is a "start_game()" function, maybe a function that is called every time a save is made could help?, although I don't know if this already exists (I don't think so).

The question is rather what is saved from the parameters and what is not.

The coordinates are adjusted at runtime. But when loading, the initial coordinates are loaded and then not replaced by the valid ones on the map.

I currently don't know whether it is even possible to query the map orientation via script.

I also noticed now that the 0,0 coordinates of the factories are not in the dialogues but the coordinates of field 0,1. I was of the opinion that field 0,0 was in the dialogues until now.

Quote from: prissi on Today at 11:45:43 AM...
So how to reproduce the error?

start the scenario tutorial
rotate map
save
load the save

run to chapter 3

Only the coordinates of the industries seem to be affected.

Yona-TYT

#26
A while ago I made a "rudimentary" function that allows you to know the current rotation, maybe this will help you?.

Note: This is already used in the tutorial


0 = North
1 = West
2 = South
3 = East
  function my_compass()
  {
    local c_max = {x = map_siz.x-1, y = map_siz.y-1}
    local c = coord(0,0)
    local text = c.tostring()

    local res_c = {x = 0, y = 0}
    local ttx = ""
    local siz = text.len()
    for(local j=0;j<siz;j++){
      local tx = format("%c",text[j])
      try {
        tx.tointeger()
      }
      catch(ev) {
        if(tx==","){
          res_c.x = ttx.tointeger()
          ttx = ""
          continue
        }
        continue
      }
      ttx+=tx
      if(j == siz-1){
        res_c.y = ttx.tointeger()
      }
    }
    //gui.add_message("Res: "+ res_c.x +" -- "+res_c.y)
    //gui.add_message("MAX: "+ c_max.x +" -- "+c_max.y)
    if(res_c.x == 0 && res_c.y == 0){
      //gui.add_message("N")
      return 0
    }
    else if(res_c.x == c_max.y && res_c.y == 0){
      //gui.add_message("W")
      return 1
    }
    else if(res_c.x == c_max.x && res_c.y == c_max.y){
      //gui.add_message("S")
      return 2
    }
    else if(res_c.x == 0 && res_c.y == c_max.x){
      //gui.add_message("E")
      return 3
    }
    return null
  }