我正在尝试在Google幻灯片中创建游戏,并且需要有一个系统,如果用户在某个幻灯片上,则会更改变量。这怎么可能?
我已经尝试使用SlidesApp.getActivePresentation().getSlides()SlidesApp.getActivePresentation().getSelection().getCurrentPage();
var currentPresentationSlide = SlidesApp.getActivePresentation().getSlides()[3];
var currentPage = SlidesApp.getActivePresentation().getSelection().getCurrentPage();
var selection = SlidesApp.getActivePresentation().getSelection();
if (currentPage = currentPresentationSlide) {
var shape = currentPresentationSlide.insertShape(SlidesApp.ShapeType.TEXT_BOX, 100, 200, 300, 60);
var textRange = shape.getText();
textRange.setText('demo');
}
我希望幻灯片将文本框(演示)放在幻灯片上(在本例中为幻灯片 3)它甚至不会将文本框放置在任何地方。
- 用户正在通过演示模式进行演示。
- 在上述情况下,您希望检索用户停留的当前页面。
我理解你的问题。不幸的是,在现阶段,由于以下原因无法实现这一目标。
- 尚无方法可以确认非所有者的用户是否仍处于演示模式。
- 演示模式尚无事件触发器。
- 您可以在此处查看有关触发器的信息。
- 运行脚本时,打开的页面将成为当前页面。这不是其他用户的页面。运行脚本时,将检索您正在打开的页面。
若要检索用户正在查看的当前页面,请使用 getSelection() 和 getCurrentPage() 方法,如下所示:
var currentPage = SlidesApp.getActivePresentation().getSelection().getCurrentPage();
注意:这是Google Apps Script文档的摘录,您现在可以在Google中轻松找到。这个SO帖子在谷歌中也被很好地引用,但似乎令人困惑。请考虑查看 Google Apps 脚本文档,详细了解您可以执行的操作。
然后,当您检查用户是否在特定幻灯片上时,请按如下方式执行条件检查:
var specialSlide = SlidesApp.getActivePresentation().getSlides()[3];
var currentPage = SlidesApp.getActivePresentation().getSelection().getCurrentPage();
if (currentPage.getObectId() === specialSlide.getObjectId()) {
// User is on a particular page
}
有一个类似的请求,我想只需单击一下即可将当前日期和时间插入演讲者备注。
这是可供您参考的可行脚本。
function addCurrentDateTimeToTheNotes() {
var now = new Date();
var selection = SlidesApp.getActivePresentation().getSelection();
var selectionType = selection.getSelectionType();
// Logger.log('selectionType: ' + selectionType);
var currentPage;
var currentSlide;
var speakerNotesShape;
var speakerNotesText;
if (selectionType == SlidesApp.SelectionType.CURRENT_PAGE) {
currentPage = selection.getCurrentPage();
}else if (selectionType == SlidesApp.SelectionType.PAGE) {
var pageRange = selection.getPageRange();
currentPage = pageRange.getPages()[0];
}else if (selectionType == SlidesApp.SelectionType.PAGE_ELEMENT) {
currentPage = selection.getCurrentPage();
}else if (selectionType == SlidesApp.SelectionType.TEXT) {
currentPage = selection.getCurrentPage();
}
if (currentPage != null) {
currentSlide = currentPage.asSlide();
speakerNotesShape = currentSlide.getNotesPage().getSpeakerNotesShape();
speakerNotesTextRange = currentSlide.getNotesPage().getSpeakerNotesShape().getText();
speakerNotesText = speakerNotesTextRange.asRenderedString();
if( !speakerNotesText || speakerNotesText.trim() === '' ){
speakerNotesTextRange.setText('Created at: rn' + now);
}else{
speakerNotesTextRange.setText('Modified at: rn' + now + 'rnrn' + speakerNotesText);
}
}
}