Showing posts with label Read. Show all posts
Showing posts with label Read. Show all posts

Saturday, May 22, 2021

【GAMEMAKER】 save and load file Create, Read, Update

 Information about object: objLineEdit

Sprite: sprController
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
set variable DisplayText to 0
set variable global.filename to "Settings.cfg"
Keyboard Event for L-key Key:
execute code:

if DisplayText=1 then exit;
var fileId
if !file_exists(global.filename) {
  fileId = file_text_open_write(global.filename);
  file_text_close(fileId);
}

f = file_text_open_read(global.filename);
LineNum=0;
while !file_text_eof(f) {
  LineNum+=1;
  Line[LineNum]=file_text_read_string(f);
  file_text_readln(f);
}
file_text_close(f);
DisplayText=1;
for (i=1; i<=LineNum; i+=1) {
  if instance_position(10,i*10+2,objEdit)=noone {
    aa=instance_create(10,i*10+2,objEdit);
    aa.LineNum=i;
  }
}
i+=3;
instance_create(20,room_height-35,objSave);
instance_create(100,room_height-35,objAddLine);
io_clear();
Draw Event:
execute code:

if DisplayText=1 {
font_size=8;
font_color=c_blue;
  for (i=1; i<=LineNum; i+=1) {
    draw_text(20,i*10,Line[i]);
  }
  font_color=c_red;
  i+=1;
  draw_text(20,i*10,"Click the button to the left of a line to edit that line.");
  i+=1;
  draw_text(20,i*10,"Click SAVE to save the file, after editing.");
} else {
font_size=24;
font_color=c_blue;
draw_text(30,20,"Press L to load file")
}

Information about object: objEdit
Sprite: sprEditButton
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Mouse Event for Left Button:
execute code:

objLineEdit.Line[LineNum]=get_string("Edit this line",objLineEdit.Line[LineNum]);
io_clear();

Information about object: objEdit
Sprite: sprEditButton
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Mouse Event for Left Button:
execute code:

objLineEdit.Line[LineNum]=get_string("Edit this line",objLineEdit.Line[LineNum]);
io_clear();

Information about object: objAddLine
Sprite: sprAddLine
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Mouse Event for Left Button:
execute code:

objLineEdit.LineNum+=1;
objLineEdit.Line[objLineEdit.LineNum]=get_string("Edit this line","");
if instance_position(10,objLineEdit.LineNum*10+2,objEdit)=noone {
  aa=instance_create(10,objLineEdit.LineNum*10+2,objEdit);
  aa.LineNum=objLineEdit.LineNum;
}
io_clear();

Generate a catchy title for a collection of newfangled music by making it your own

Write a newfangled code fragment at an earlier stage to use it. Then call another method and make sure their input is the correct one. The s...